#When adding effects directly in on_actions always consider if it would be best to do so through a scripted effect. on_actions with a lot of script in them are harder to get an overview of.

# country
on_startup = {
	if = {
		limit = {
			current_age = age_of_discovery
		}
		LXA = {
			if = {
				limit = {
					NOT = { has_country_flag = lxa_loyalty_flag }
				}
				add_estate_loyalty = {
					estate = estate_church
					loyalty = -10
				}
				set_country_flag = lxa_loyalty_flag
			}
		}
	}
	emperor = {
		save_global_event_target_as = Emperor
	}
	if = {
		limit = {
			is_emperor_of_china = yes
		}
		save_global_event_target_as = EmperorOfChina
	}
	events = {
		muslim_school_events.20 #Pick School
	#flavor_fra.15000 #Make the French Revolution happen if starting in 1789
	}
	if = {
		limit = {
			has_dlc = "Cradle of Civilization"
			has_country_modifier = tur_janissary
		}
		remove_country_modifier = tur_janissary
	}
	initialize_schools_effect = yes #This is only used here but is used for readability of on_action file.

	if = {
		limit = {
			NOT = { has_country_flag = new_flavour_bav_13_has_been_triggered }
			OR = {
				tag = UBV
				tag = LBV
				tag = ING
			}
		}
		set_country_flag = new_flavour_bav_13_has_been_triggered
		country_event = { id = new_flavour_bav.13 days = 90 } #better not to allow almost instant DOWs
	}
	if = {
		limit = {
			tag = FRA
			started_in = 1789.7.14
			NOT = { is_year = 1790 }
			NOT = { has_disaster = french_revolution }
		}
		add_disaster_progress = {
			value = 100
			disaster = french_revolution
		}
	}
	if = {
		limit = {
			exists = SUK
		}
		SUK = {
			set_ruler_flag = suk_monarch_flag
		}
		AYU = {
			set_country_flag = ayu_monarch_flag
		}
	}
}

# country
on_religion_change = {
	on_religion_change_estate_privileges_effect = yes
	judaism_on_religion_change_effect = yes
	###removes catholic modifiers
		remove_country_modifier = counter_reformation
		remove_country_modifier = the_statue_in_restraint_of_appeals
		remove_country_modifier = revocation_of_restraint_of_appeals
		remove_country_modifier = bavarian_jesuits
		remove_country_modifier = the_societas_jesu
		remove_country_modifier = the_declaration_of_indulgence
		remove_country_modifier = de_heretico_comburendo
		remove_country_modifier = the_conventicle_act
	if = {
		limit = {
			has_reform = indian_sultanate_reform
			NOT = { religion_group = muslim }
		}
		remove_government_reform = indian_sultanate_reform
	}

	if = {
		limit = {
			has_reform = feudal_theocracy
			NOT = { religion_group = muslim }
			NOT = { religion_group = zoroastrian_group }
		}
		remove_government_reform = feudal_theocracy
	}

	if = {
		limit = {
			government = native
			OR = {
				religion = nahuatl
				religion = mesoamerican_religion
				religion = inti
			}
		}
		change_government = monarchy
		add_government_reform = autocracy_reform
	}


	if = {
		limit = {
			has_heir = yes
		}
		set_heir_religion = ROOT
	}
	if = {
		limit = {
			has_regency = no
		}
		set_ruler_religion = ROOT
	}
	if = {
		limit = {
			has_dlc = "Rights of Man"
			has_consort = yes
		}
		set_consort_religion = ROOT
	}
	if = {
		limit = {
			NOT = { religion = orthodox }
		}
		every_known_country = {
			limit = {
				reverse_has_opinion_modifier = {
					who = ROOT
					modifier = closed_down_the_patriarchate
				}
			}
			reverse_remove_opinion = {
				who = ROOT
				modifier = closed_down_the_patriarchate
			}
		}
	}
	if = {
		limit = {
			religion = catholic
			has_ruler_flag = personal_catholic_sympathies
		}
		country_event = { id = protestantism_events.19 }
	}
	if = {
		limit = {
			religion = protestant
		}
		set_country_flag = converted_to_protestantism
	}
	if = {
		limit = {
			religion = hussite
		}
		remove_country_modifier = hussite_persecution
	}
	if = {
		limit = { has_country_modifier = bav_religious_mandate_mod }
		remove_country_modifier = bav_religious_mandate_mod
	}
	add_country_modifier = {
		name = recently_changed_religion_dummy
		duration = 10
		hidden = yes
	}
	if = {
		limit = {
			NOT = { religion_group = muslim }
			any_owned_province = { has_province_modifier = sufi_shrine }
		}
		every_owned_province = {
			limit = { has_province_modifier = sufi_shrine }
			remove_province_modifier = sufi_shrine
		}
	}
	if = {
		limit = {
			religion = shamanism
			has_country_modifier = son_fetishism_as_secondary_religion
		}
		remove_country_modifier = son_fetishism_as_secondary_religion
		every_owned_province = {
			limit = {
				has_province_modifier = son_fetishism_as_secondary_religion_province
			}
			remove_province_modifier = son_fetishism_as_secondary_religion_province
		}
	}
	events = {
		muslim_school_events.20 #Pick School
		propagate_religion_events.7 #Propagated Country is now Muslim
	}
}

# country.
on_secondary_religion_change = {
	# Done from code: add_prestige = -50 (Define: CHANGE_SECONDARY_PRESTIGE_HIT)
	every_owned_province = {
		limit = { has_province_modifier = tengri_monastic_order }
		remove_province_modifier = tengri_monastic_order
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_shiite_settled_in_capital }
		remove_province_modifier = tengri_shiite_settled_in_capital
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_insincere_leadership }
		remove_province_modifier = tengri_insincere_leadership
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_religious_influx }
		remove_province_modifier = tengri_religious_influx
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_ruler_questioned }
		remove_province_modifier = tengri_ruler_questioned
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_strengthened_local_clans }
		remove_province_modifier = tengri_strengthened_local_clans
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_growing_cities }
		remove_province_modifier = tengri_growing_cities
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_christian_mission }
		remove_province_modifier = tengri_christian_mission
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_unchristian_values }
		remove_province_modifier = tengri_unchristian_values
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_monastic_order }
		remove_province_modifier = tengri_monastic_order
	}
	every_owned_province = {
		limit = { has_province_modifier = hindufication }
		remove_province_modifier = hindufication
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_influx_of_monks }
		remove_province_modifier = tengri_influx_of_monks
	}
	every_owned_province = {
		limit = { has_province_modifier = tengri_abandoning_the_old_ways }
		remove_province_modifier = tengri_abandoning_the_old_ways
	}
	remove_country_modifier = tengri_devout_muslim
	remove_country_modifier = tengri_confucian_elites_alienated
	remove_country_modifier = tengri_confucian_titles
	remove_country_modifier = tengri_traditionalists_strengthened
	remove_country_modifier = tengri_confucian_nobles
	remove_country_modifier = tengri_pali_legal_traditions
	remove_country_modifier = tengri_religious_pilgrimages
	remove_country_modifier = tengri_monks_in_capital
	remove_country_modifier = tengri_influx_of_monks
	remove_country_modifier = tengri_shiite_immigration
	remove_country_modifier = support_of_the_khojas
	remove_country_modifier = black_shamanism_modifier
	remove_country_modifier = tengri_animist_pantheon
	remove_country_modifier = zoroastrian_traders
	remove_country_modifier = spread_of_tengri_tea_ceremony
	remove_country_modifier = tengri_tea_ceremony
	remove_country_modifier = tengri_japanese_swordsmithing
	remove_country_modifier = tengri_bow_and_arrow_defended
	remove_country_modifier = tengri_support_of_shamans
	remove_country_modifier = tengri_hindu_conflict
	remove_country_modifier = tengri_hindu_syncretism
	remove_country_modifier = tengri_devout_christian_ruler
	remove_country_modifier = tengri_personal_confessor
	remove_country_modifier = tengri_confucian_administrators
	remove_country_modifier = tengri_traditional_elites_alienated
	remove_country_modifier = tengri_jihad
	remove_country_modifier = tengri_stood_up_for_yassa
	remove_country_modifier = tengri_sufi_teacher
	remove_country_modifier = tengri_qadi
	remove_country_modifier = tengri_religious_influx
	remove_country_modifier = tengri_ibadi_scholars
	remove_country_modifier = tengri_clergy_conflicts
	remove_country_modifier = tengri_shamans_spurned
	clr_country_flag = khojas_established
	clr_country_flag = tengri_christian_devout_court
	clr_ruler_flag = tengri_muslim_ruler_questioned
	if = {
		limit = {
			check_variable = { which = khojas_retained value = 1 }
		}
		set_variable = {
			which = khojas_retained value = 0
		}
	}
}

# country. Spawned when Enforcing Rebel Demands through a Support Rebels-war.
on_enforce_rebel_demands = {
	# ROOT = The winning country
	# FROM = The loosing country
	set_country_flag = helped_rebels_win_war
}

# country
on_colonial_liberation = {
	if = {
		limit = {
			NOT = { has_country_flag = old_world_to_new_world_flag }
		}
		country_event = { id = colonial_nation.90 days = 1 }
	}
}

# country
on_colonial_reintegration = {
	events = {
		colonial_nation.91
	}
}

# country
on_peace_actor = {
	events = {
		usa_dlc.36				# Evacuation Day
		native_americans.7		# Appoint Peace Chief
	}
}

# country
on_peace_recipient = {
	events = {
		native_americans.7		# Appoint Peace Chief
	}
}

# country
# root = winning country, from = loser country
on_war_won = {
	FROM = { country_event = { id = flavor_cri.6 } }
	ROOT = { country_event = { id = tributary_events.32 } }
	
	if = {
		limit = {
			is_part_of_hre = yes
			FROM  = { is_part_of_hre = yes }
		}
		ROOT = { save_global_event_target_as = hre_winner }
		FROM = { save_global_event_target_as = hre_loser }
		random_known_country = {
			limit = {
				has_reform = free_city
				NOT = {
					prestige = 40
				}
				NOT = {
					has_country_modifier = fc_treatyconference_timer
				}
			}
			add_country_modifier = {
				name = fc_treatyconference_timer
				duration = 3650
				hidden = yes
			}
			country_event = {
				id = free_cities.7
				days = 7
			}
		}
	}

	if = {
		limit = {
			tag = MLO
			NOT = { has_country_flag = emp_mlo_won_war_with_swiss_mercs }
			any_hired_mercenary_company = {
				home_province = {
					OR = {
						area = switzerland_area
						area = romandie_area
					}
				}
			}
		}
		set_country_flag = emp_mlo_won_war_with_swiss_mercs
	}
	
	if = {
		limit = {
			is_hiring_condottiere_from = SWI
		}
		SWI = { set_country_flag = won_condottiere_war }
		if = {
			limit = {
				tag = PAP
			}
			SWI = {
				set_country_flag = hired_to_pope
			}
		}
	}
	
	if = {
		limit = {
			primary_culture = melanesian
			NOT = { has_country_modifier = warlord_mod }
		}
		FROM = {
			country_event = {
				id = polynesian.17
			}
		}
	}
	if = {
		limit = {
			ROOT = {
				religion = jewish
				has_church_aspect = judaism_purim_teachings_aspect
			}
		}
		add_church_power = 10
	}
}

# country
# root = loser country, from = winner country
on_war_lost = {
	ROOT = { country_event = { id = flavor_cri.6 } }
	ROOT = { country_event = { id = tributary_events.32 } }
	if = {
        limit = {
            government = republic
            is_lesser_in_union = yes
		}
		change_government_to_monarchy = yes
    }
	if = {
		limit = {
			FROM = { is_emperor = yes }
			NOT = { has_country_flag = reined_in_for_shadow_kingdom }
			NOT = { has_global_flag = italians_leave_hre }
			is_emperor = no
			is_part_of_hre = yes
			OR = {
				capital_scope = { region = italy_region }
				AND = {
					culture_group = latin
					any_owned_province = {
						region = italy_region
					}
				}
			}
		}
		set_country_flag = reined_in_for_shadow_kingdom
	}
	add_country_modifier = {
		name = just_lost_war_timer
		duration = 10
		hidden = yes
	}
}

# country
# root = winning country, from = loser country
on_battle_won_country = {
	if = {
		limit = {
			ROOT = {
				tag = ALB
				NOT = { has_country_flag = albanian_victory }
			}
			FROM = {
				tag = TUR
			}
		}
		ROOT = { set_country_flag = albanian_victory }
	}
	if = {
		limit = {
			ROOT = {
				religion = jewish
				has_church_aspect = judaism_purim_teachings_aspect
			}
		}
		ROOT = {
			add_war_exhaustion = -0.05
		}
	}
}

# country
# root = loser country, from = winner country
on_battle_lost_country = {
	battle_cult_spreading_effect = yes #Scripted effect for fetishist cult mechanics.
	random_events = {
		90 = 0
		10 = friendship_events.1 #Historical Friendship Broken
	}
}

# province
# root = location, from = loser country
on_battle_won_province = {
	if = {
		limit = {
			from = { tag = REB }
			owner = {
				tag = ENG
				has_disaster = war_of_the_roses
				has_country_modifier = wotr_one_year_timer
				NOT = { has_country_flag = war_of_the_roses_pretender_fled }
			}
		}
		owner = { country_event = { id = war_of_the_roses.200 days = 2 } }
	}
	if = {
		limit = {
			from = {
				tag = REB
				is_rebel_type = revolutionary_rebels
			}
			owner = {
				any_owned_province = {
					region = root
					has_revolution_in_province = yes
				}
				NOT = { has_disaster = french_revolution }
				NOT = { has_disaster = revolution }
				NOT = { has_spawned_rebels = revolutionary_rebels }
			}
		}
		owner = { country_event = { id = center_of_revolution.1600 } }
	}
	random_events = {
		1000 = 0
		100 = war_of_the_roses.6	# WotR - Rebel Leaders Captured
	}
}

#Unit Scope OnAction for Battle Won
on_battle_won_unit = {
	if = {
		limit = {
			unit_owner = { ai = no } #Scopes to Unit Owner from Unit Scope
			general_with_steam_name = yes #Unit Scope Trigger
		}
		unit_owner = { set_country_flag = general_with_steam_name_won_battle }
	}
	if = {
		limit = {
			general_with_name = "Damarwulan"
		}
		unit_owner = {
			change_variable = {
				which = DamarwulanWinVariable 
				value = 1
			}
		}
	}
	if = {
		limit = {
			general_with_name = "Damarwulan"
			unit_owner = {
				check_variable = {
					which = DamarwulanWinVariable
					value = 5
				}
			}
		}
		unit_owner = {
			country_event = { id = majapahit.2 days = 2 }
		}
	}
	if = {
		limit = {
			unit_owner = {
				mission_completed = son_military_expertise
				NOT = { mission_completed = son_win_battles }
			}
		}
		unit_owner = {
			change_variable = {
				which = son_fight_counter
				value = 1
			}
		}
		if = {
			limit = {
				is_ruler_commanding_unit = yes
			}
			unit_owner = {
				change_variable = {
					which = son_fight_counter
					value = 1
				}
			}
		}
	}
}

# #Unit Scope OnAction for Battle Lost
on_battle_lost_unit = {
    if = {
        limit = {
            unit_owner = {
                tag = MNG
                has_ruler_flag = mng_militry_incompetence
            }
            is_ruler_commanding_unit = yes
			enemy_unit = {
				unit_owner = {
					tag = OIR
				}
			}
        }
        OIR = {
            country_event = { id = flavor_oir.2 }
        }
    }
}

# province
# root = location, from = country doing it
on_added_to_trade_company ={

}

# province
# root = location, from = country doing it
on_removed_from_company ={

}

# province
# root = location, from = country doing it
on_company_formed ={

}

# province
# root = location, from = country doing it
on_company_disolved ={

}

# province
# root = location, from = winner country
on_battle_lost_province = {
	random_events = {
		1000 = 0
		100 = tyw_events.22	# Capital Battle in Religious War
	}
}

# country
# root = winning country, from = location
on_siege_won_country = {
	if = {
		limit = {
			from = { owned_by = SAX }
			OR = {
				is_in_war = {
					defenders = root
					defenders = THU
					defenders = emperor
					attackers = SAX
				}
				is_in_war = {
					attackers = root
					attackers = THU
					attackers = emperor
					defenders = SAX
				}
			}
			THU = {
				dynasty = "von Wettin"
				is_elector = no
				is_emperor = no
				alliance_with = emperor
			}
			SAX = {
				is_elector = yes
				all_owned_province = {
					NOT = { controlled_by = SAX }
					OR = {
						controlled_by = THU
						controller = {
							OR = {
								is_in_war = {
									defenders = this
									defenders = THU
									defenders = emperor
									attackers = SAX
								}
								is_in_war = {
									attackers = this
									attackers = THU
									attackers = emperor
									defenders = SAX
								}
							}
						}
					}
				}
			}
		}
		THU = { country_event = { id = flavor_sax.10 } } # Ask Emperor for Saxon Electorate
	}
	if = {
		limit = {
			ROOT = {
				religion = jewish
				has_church_aspect = judaism_remember_passover_aspect
			}
			FROM = {
				owner = {
					war_with = ROOT
				}
				fort_level = 1
			}
		}
		ROOT = {
			add_church_power = 5
		}
	}
	grant_manpower_from_capital_slave_raid = yes
	events = {
		tyw_events.14 # Fall of Prague in Religious War
		flavor_oir.5 # Oirats capture Beijing
		flavor_lna.1 # Emerald Buddha
		flavor_son.14 # Djenne surrenders to Songhai Trigger
	}
	random_events = {
		10 = army_professionalism_events.1 #City Sacked
		100 = 0
	}
}

# country
# root = losing country, from = location
on_siege_lost_country = {
	events = {
		curia.8
		papacy_events.5
	}
}

# province
# root = location, from = losing country
on_siege_won_province = {
	events = {
		synthetic_dawn.4
	}
	if = {
		limit = {
			from = {
				tag = REB
				is_rebel_type = revolutionary_rebels
			}
			owner = {
				any_owned_province = {
					region = root
					has_revolution_in_province = yes
				}
				NOT = { has_disaster = french_revolution }
				NOT = { has_disaster = revolution }
				NOT = { has_spawned_rebels = revolutionary_rebels }
			}
		}
		owner = { country_event = { id = center_of_revolution.1600 } }
	}
}

# province
# root = location, from = winning country
on_siege_lost_province =  {
	events = {
		war_of_the_roses.10		# Lancaster Stronghold
		war_of_the_roses.11		# York Stronghold
		french_wars_of_religion.7 #Ravening Religious Fanatics
		french_wars_of_religion.9 #french_wars_of_religion.9
	}
}

# province
# root = location, from = country that abandons colony
# Fired right before the colony is abandoned.
on_abandon_colony = {
}

# province
# root = location, from = country that owns it
# Fired right after the great project is constructed
on_great_project_constructed = {
}

# OBS: Consider that the following on_actions can be called for Personal Union juniors as well.
# country
on_new_monarch = {
	crimean_succession_effect = yes #Scripted effect
	slesvig_question_effect = yes #Scripted effect
	if = {
		limit = {
			has_consort_regency = no
			any_owned_province = {
				has_province_modifier = domain_of_spouses_family
			}
		}
		every_owned_province = {
			limit = { has_province_modifier = domain_of_spouses_family }
			remove_province_modifier = domain_of_spouses_family
		}
	}
	if = {
		limit = {
			has_consort_regency = no
			any_owned_province = {
				has_province_modifier = home_of_consort
			}
		}
		every_owned_province = {
			limit = { has_province_modifier = home_of_consort }
			remove_province_modifier = home_of_consort
		}
	}
	if = {
		limit = {
			NOT = { has_dlc = "Mandate of Heaven" }
			has_country_modifier = the_mandate_of_heaven
			NOT = { legitimacy = 80 }
		}
		country_event = { id = china_events.32 }	# History of last ruler
	}
	if = {
		limit = {
			religion = jewish
		}
		clr_country_flag = ruler_is_messiah
	}
	# ambrosian_republic_effect = yes
	succession_culture_religion_effect = yes
	sheik_ul_islam_effect = yes
	hab_remove_mission_mods_if_not_emperor_effect = yes
	thu_remain_von_wettin_effect = yes
	ladislaus_postumus_union_effect = yes
	if = {
		limit = { has_any_heir_cult_active = yes }
		remove_heir_cult = yes
	}
	events = {
		tribal_succession.1		# Harsh anti-tribals.
		9492 					# Remove some event modifiers
		flavor_boh.8			# Winter King in Prague
		flavor_kol.1			# Bavarian Archbishop
		war_of_the_roses.101	# WotR - House of Lancaster wins
		war_of_the_roses.102	# WotR - House of York wins
		war_of_the_roses.106	# WotR - Another dynasty has seized the throne
		flavor_tur.102			# Janissary Reward
		flavor_ori.7			# Hamvira Victorious
		flavor_kbo.1			# The two branches of the Sayfawa dynasty
		flavor_kbo.8			# Sayfawa pretenders
		flavor_zan.5			# Coup of Coup of Suleiman and Muhammad al-Mazlum.
		purple_phoenix.1		# BYZ pretenders
		flavor_pol.3480			# The Pacta Conventa
		protestantism_events.15	# Catholic Leaning Monarch
		tengri_events.17		# Keep the Khojas in Power?
		flavor_tus.15			# Savonarola Dies
		flavor_brapru.22		# Succession of Albrecht Achilles
		flavor_brapru.25		# Dispositio Achillea (can also trigger from flavor_brapru.22)
		flavor_nor.27			# Proclamation in Hamar
		china_events.43			# Picking new Capital for China
		celestial_empire_events.3 #Resistance to Sinicization
		flavor_boh.2			#Heretic Kings
		flavor_hun.17			#Maintaining the Black Army
		flavor_tim.1			#Death of Shah Rukh
		muslim_school_events.20 #No Religious School
		flavor_daimyo.4			#Shiba Yoshikado
		flavor_fra.9000			# François Villon
	}
	random_events = {
		1000 = 0
		100 = flavor_kol.1		# Bavarian Archbishop
		100 = flavor_hsa.3		# Hansa: Tagfahrt
		100 = inti_events.1		# Birth of a Panaca
		50 = dynastic_events.4
		50 = dynastic_events.5
		25 = harem_events.7		#Failed Policy of Fratricide
	}
}

on_new_consort = {
	country_event = { id = consort_events.2 }
	if = {
		limit = { has_ruler_flag = had_10_years_anniversary }
		clr_ruler_flag = had_10_years_anniversary
	}
	if = {
		limit = { has_ruler_flag = had_20_years_anniversary }
		clr_ruler_flag = had_20_years_anniversary
	}
	if = {
		limit = { has_ruler_flag = consort_had_affection_of_ruler }
		clr_ruler_flag = consort_had_affection_of_ruler
	}
	if = {
		limit = { has_country_modifier = sought_after_bachelor }
		remove_country_modifier = sought_after_bachelor
	}
	random_events = {
		1000 = 0
		25 = polynesian.16 #fijian marriage
	}
}

# country
on_monarch_death = {
	if = {
		limit = {
			tag = ANS
			BRA = {
				has_country_flag = albrecht_achilles_flag
			}
		}
		BRA = {
			clr_country_flag = albrecht_achilles_flag #Just to be sure
			kill_heir = {} #If Albrecht Achilles dies in Ansbach he will also be dead in Brandenburg, will appear as normal death of heir to BRA.
		}
	}
	if = {
		limit = { has_country_modifier = sought_after_bachelor }
		remove_country_modifier = sought_after_bachelor
	}
	if = {
		limit = {
			tag = SAX
			has_country_flag = sax_thuringen_split_to_happen
			OR = {
				NOT = { dynasty = "von Wettin" }
				NOT = { senior_union_with = THU }
				has_regency = yes
			}
		}
		clr_country_flag = sax_thuringen_split_to_happen
	}
	if = {
		limit = { tag = SAM }
		country_event = { id = polynesian.35 }
	}
	if = {
		limit = { tag = TOG }
		country_event = { id = polynesian.36 }
	}
	if = {	# Ascension of Trailokanat	
		limit = { tag = AYU }
		country_event = { id = flavor_suk.1 }		 			
	}
	burgundian_inheritance_start_effect = yes
	ladislaus_postumus_king_died_effect = yes
	if = {
		limit = {
			OR = {
				has_country_flag = no_stab_hit_on_ruler_death
				has_a_primary_cult_selected = yes
			}
			OR = {
				government = tribal
				government = monarchy
			}
		}
		add_stability = 1
	}
	events = {
		flavor_wal.1 # Vlad the Impaler. So that he doesn't try to usurp his father.
		flavor_nav.4 # Navarra succession event
		flavor_sax.8 # Treaty of Leipzig
		flavor_pap.16 # Borgia Pope
		flavor_pap.19 # death of borgia pope
		flavor_tus.22 # Medici Pope
		flavor_tus.24 # death of the Medici Pope
		majapahit.8 # Majapahit pretenders
		flavor_mal.11 # Mali pretenders
		flavor_mal.47 # Pilgrimage ends prematurely
	}
}

# country
on_regent = {
	if = {
		limit = {
			NOT = { has_global_flag = death_of_haji_giray } #Also set in history.
			tag = CRI
			exists = TUR
			is_subject = no
			TUR = {
				num_of_cities = ROOT
				is_subject = no
				num_of_ports = 1
			}
		}
		country_event = { id = flavor_cri.1 } #Death of Haji Giray
	}
	if = {
		limit = {
			NOT = { has_global_flag = death_of_haji_giray } #Also set in history.
			tag = CRI
			OR = {
				NOT = { exists = TUR }
				is_subject = yes
				TUR = { NOT = { num_of_cities = ROOT } }
				TUR = { is_subject = yes }
				TUR = { NOT = { num_of_ports = 1 } }
			}
		}
		set_global_flag = death_of_haji_giray
	}
	events = {
		tribal_succession.1	# harsh anti-tribals.
		flavor_tim.1			#Death of Shah Rukh
		flavor_daimyo.4			#Shiba Yoshikado
	}
}

# country
on_extend_regency = {
}

# country
on_new_term_election = {
	events = {
		700		# Election event
		elections.720		# Dutch Republic
		elections.800	# Lottery election
		pirates.1
	}
}

# country
on_death_election = {
	if = {
		limit = { has_reform = presidential_despot_reform }
		remove_government_reform = presidential_despot_reform
	}
	if = {
		limit = {
			has_reform = pirate_republic_reform
		}
		set_country_flag = pirate_death_election
		country_event = { id = pirates.1 }
	}
	events = {
		701		# Election event
		elections.721		# Dutch Republic
		elections.800	# Lottery election
		flavor_tus.16 #Savonarola Leaves This World
	}
}

# country
on_death_foreign_slave_ruler = {
	events = {
		mamluk_events.0 # Choose new ruler
	}
}

# country
on_replace_governor = {
	events = {
		elections.707
	}
}


# country
on_bankruptcy = {
}

# country (country annexing, root = target)
on_diplomatic_annex = {
	events = {
		610
	}
}

# country
on_heir_death = {
	if = {
		limit = { has_country_flag = heir_dip_education }
		clr_country_flag = heir_dip_education
	}
	if = {
		limit = { has_country_flag = heir_mil_education }
		clr_country_flag = heir_mil_education
	}
	if = {
		limit = { has_country_flag = heir_adm_education }
		clr_country_flag = heir_adm_education
	}
	if = {
		limit = { has_ruler_flag = well_advised_tutored_heir }
		clr_ruler_flag = well_advised_tutored_heir
	}
	if = {
		limit = { has_ruler_flag = heir_went_on_grand_tour }
		clr_ruler_flag = heir_went_on_grand_tour
	}
	if = {
		limit = { has_country_flag = albrecht_achilles_flag }
		clr_country_flag = albrecht_achilles_flag #Death of original Albrecht Achilles
	}
	if = {
		limit = { has_ruler_flag = sancaga_cikma }
		clr_ruler_flag = sancaga_cikma
		every_owned_province = {
			limit = {
				has_province_modifier = heir_in_training
			}
			remove_province_modifier = heir_in_training
		}
	}
	if = {
		limit = { has_ruler_flag = returned_from_sancaga_sikma_province }
		clr_ruler_flag = returned_from_sancaga_sikma_province
	}
	ladislaus_postumus_heir_died_effect = yes
	if = {
		limit = { primary_culture = maori }
		country_event = { id = polynesian.26 }
	}
	if = {
		limit = { has_any_heir_cult_active = yes }
		remove_heir_cult = yes
	}
}

# country
on_queen_death = {

	if = {
		limit = { has_consort_flag = 10_years_anniversary }
		set_ruler_flag = had_10_years_anniversary
	}
	if = {
		limit = { has_consort_flag = 20_years_anniversary }
		set_ruler_flag = had_20_years_anniversary
	}
	if = {
		limit = { has_consort_flag = consort_has_affection_of_ruler }
		set_ruler_flag = consort_had_affection_of_ruler
	}

	if = {
		limit = {
			has_regency = no
			NOT = { has_ruler_flag = widow_widower }
		}
		set_ruler_flag = widow_widower
	}
	if = {
		limit = { has_consort_regency = no }
		random_owned_province = {
			limit = { has_province_modifier = domain_of_spouses_family }
			remove_province_modifier = domain_of_spouses_family
		}
	}
	if = {
		limit = { has_ruler_flag = accepted_help_from_spouses_family }
		clr_ruler_flag = accepted_help_from_spouses_family
	}
	if = {
		limit = { has_ruler_flag = helped_spouses_family }
		clr_ruler_flag = helped_spouses_family
	}
	if = {
		limit = { has_ruler_flag = refused_to_help_spouses_family }
		clr_ruler_flag = refused_to_help_spouses_family
	}
	if = {
		limit = { has_ruler_flag = has_lowborn_consort }
		random_owned_province = {
			limit = { has_province_modifier = home_of_consort }
			remove_province_modifier = home_of_consort
		}
	}
	if = {
		limit = { has_ruler_flag = has_lowborn_consort }
		clr_ruler_flag = has_lowborn_consort
	}
	if = {
		limit = { has_country_modifier = consort_adm_advice }
		remove_country_modifier = consort_adm_advice
	}
	if = {
		limit = { has_country_modifier = consort_dip_advice }
		remove_country_modifier = consort_dip_advice
	}
	if = {
		limit = { has_country_modifier = consort_mil_advice }
		remove_country_modifier = consort_mil_advice
	}
	if = {
		limit = { has_country_modifier = without_spouse_advice }
		remove_country_modifier = without_spouse_advice
	}
	if = {
		limit = { has_ruler_modifier = affectionate_royal_couple }
		remove_country_modifier = affectionate_royal_couple
	}
	if = {
		limit = { has_ruler_modifier = bav_woman_scorned_mod }
		remove_country_modifier = bav_woman_scorned_mod
	}
	if = {
		limit = { has_ruler_modifier = bav_building_wife_church }
		remove_country_modifier = bav_building_wife_church
	}
	clr_ruler_flag = marriage_length
}

# country
on_new_heir = {
	if = {
		limit = { has_any_heir_cult_active = yes }
		remove_heir_cult = yes
	}
	if = {
		limit = {
			has_country_flag = enabled_cult_for_heirs
		}
		country_event = {
			id = fetishist_flavor.600
		}
	}
	if = {
		limit = {
			has_country_flag = had_bmv
		}
		clr_country_flag = had_bmv
	}
}

# country
on_weak_heir_claim = {
	events = {
		611		# Pretenders rise up
	}
}

# country : no heir in theocracy
on_heir_needed_theocracy = {
	events = {
		theocracy.1
	}
}

# Emperor from same dynasty
on_successive_emperor = {
	emperor = {
		save_global_event_target_as = Emperor
	}
	events = {
		900
	}
}

# Called whenever a new emperor is elected
# FROM = Previous Emperor
# ROOT = New Emperor 
on_emperor_elected = {
	every_elector = {
		if = {
			limit = {
				preferred_emperor = root
			}
			change_variable = {
				which = supported_successive_emperors
				value = 1
			}
		}
		else = {
			set_variable = {
				which = supported_successive_emperors
				value = 0
			}
		}
	}

	emperor = {
		save_global_event_target_as = Emperor
	}
	FROM = {
		if = {
			limit = { has_country_modifier = diet_occupied }
			remove_country_modifier = diet_occupied
			ROOT = {
				add_country_modifier = { name = diet_occupied duration = -1 }
			}
		}
		if = {
			limit = {
				any_country = {
					reverse_has_opinion_modifier = {
						modifier = opinion_imperial_diplomacy
						who = prev
					}
				}
			}
			every_country = {
				limit = {
					reverse_has_opinion_modifier = {
						modifier = opinion_imperial_diplomacy
						who = prev
					}
				}
				reverse_remove_opinion = {
					modifier = opinion_imperial_diplomacy
					who = prev
				}
				ROOT = {
					add_opinion = {
						modifier = opinion_imperial_diplomacy
						who = prev
					}
				}
			}
		}
	}
}

# HRE Prince released by the emperor
on_released_hre_member = {
	events = {
	}
}

# HRE Prince converts to non-Emperor religion
on_hre_member_false_religion = {
	events = {
	}
}

# HRE Prince converts to Emperor religion
on_hre_member_true_religion = {
	events = {
	}
}

# Emperor wins HRE defensive war
on_hre_wins_defensive_war = {
	events = {
	}
}

# HRE member annexed by non-HRE country
on_hre_member_annexed = {
	events = {
	}
}

# HRE member released from non-HRE vassalage
on_hre_released_vassal = {
	events = {
	}
}

# HRE member transferred from non-HRE vassalage to Emperor
on_hre_transfered_vassal = {
	events = {
	}
}

# Emperor coming to the defense of a HRE member
on_hre_defense = {
	events = {
	}
}

# Emperor NOT coming to the defense of a HRE member
on_hre_non_defense = {
	events = {
		909
	}
}

# HRE Member takes a HRE province from an outs100e country in a peace (province scope)
on_hre_province_reconquest = {
	events = {
	}
}

on_lock_hre_religion = {
	events = {
		religious_leagues.1
		religious_leagues.8
	}
}

on_change_hre_religion = {
	events = {
		religious_leagues.2
		religious_leagues.3
	}
}

on_hre_religion_white_peace = {
	events = {
		religious_leagues.4
	}
}

# When a non-native changes government type
on_government_change = {
	clr_country_flag = pirate_mutineer_council
	clr_country_flag = caretaker_revolutionary_government
	if = {
		limit = {
			NOT = { government = monarchy }
			any_owned_province = {
				has_province_modifier = domain_of_spouses_family
			}
		}
		random_owned_province = {
			limit = { has_province_modifier = domain_of_spouses_family }
			remove_province_modifier = domain_of_spouses_family
		}
	}
	if = {
		limit = {
			NOT = { government = monarchy }
			any_owned_province = {
				has_province_modifier = home_of_consort
			}
		}
		random_owned_province = {
			limit = { has_province_modifier = home_of_consort }
			remove_province_modifier = home_of_consort
		}
	}
	if = {
		limit = {
			OR = {
				tag = ENG
				tag = GBR
			}
			any_owned_province = {
				has_province_modifier = rotten_borough
			}
		}
		every_owned_province = {
			limit = {
				has_province_modifier = rotten_borough
			}
			remove_province_modifier = rotten_borough
		}
	}
	if = {
		limit = { has_country_modifier = the_reign_of_terror }
		remove_country_modifier = the_reign_of_terror
	}
	if = {
		limit = {
			has_global_flag = great_peasants_war_flag
			is_part_of_hre = yes
			has_reform = peasants_republic
		}
		1 = {
			change_variable = {
				which = GPW_counting_variable
				value = -3
			}
		}
	}
}

# When a native changes government after filling all their advancement groups.
on_native_change_government = {
}

# Nation is integrated after being in union
on_integrate = {
	events = {
		610
	}
}

# Nation annexed.
# FROM is the nation being annexed
on_annexed = {
	events = {
		celestial_empire_events.1 # Empire dismantled
	}
	on_annexed_estate_privileges_effect = yes
	FROM = {
		if = {
			limit = { is_emperor_of_china = yes }
			dismantle_empire_of_china = yes
			set_global_flag = empire_of_china_dismantled
		}
		if = {
			limit = { has_country_modifier = legatus_natus }
			remove_country_modifier = legatus_natus
			set_global_flag = no_legatus_natus
		}
		if = {
			limit = { has_country_modifier = primas_germaniae }
			remove_country_modifier = primas_germaniae
			set_global_flag = no_primas_germaniae
		}
	}
}

# When the chinese empire gets dismantled (e.g. when the emperor is annexed)
# FROM = Emperor, ROOT = Current Nation
on_chinese_empire_dismantled = {
	clear_global_event_target = EmperorOfChina
	events = {
	}
}

# When a nation gains the Mandate of Heaven (becomes the Emperor of China)
# FROM = Old Emperor, ROOT = New Emperor
on_mandate_of_heaven_gained = {
	save_global_event_target_as = EmperorOfChina
	if = {
		limit = {
			technology_group = nomad_group
		}
		change_technology_group = chinese
		change_unit_type = chinese
	}
	if = {
		limit = {
			OR = {
				NOT = { government = monarchy }
				government = tribal
			}
		}
		change_government_to_monarchy = yes
	}
	add_government_reform = celestial_empire
	set_mandate = 60
	set_meritocracy = 60
	add_country_modifier = {
		name = new_mandate_holder
		duration = 9125
	}
	1816 = {
		if = {
			limit = {
				NOT = { owned_by = root }
				NOT = { is_core = root }
			}
			add_core = root
		}
	}
	1821 = {
		if = {
			limit = {
				NOT = { owned_by = root }
				NOT = { is_core = root }
			}
			add_core = root
		}
	}
	667 = {
		if = {
			limit = {
				NOT = { owned_by = root }
				NOT = { is_core = root }
			}
			add_core = root
		}
	}
	china_superregion = {
		limit = {
			NOT = { is_core = ROOT }
		}
		add_permanent_claim = ROOT
	}
	if = {
		limit = {
			has_dlc = "Mandate of Heaven"
		}
		remove_faction = temples
		remove_faction = enuchs
		remove_faction = bureaucrats
	}
	if = {
		limit = {
			has_country_modifier = lost_mandate_of_heaven
		}
		remove_country_modifier = lost_mandate_of_heaven
	}
	country_event = { #Reforming the Bureaucracy
		id = china_events.31
		days = 365
	}
	country_event = {
		id = china_events.32 #Records of the last Empire
		days = 183
	}
	country_event = {
		id = celestial_empire_events.2
		days = 1825
	}
}

# When a nation loses the Mandate of Heaven
# FROM = New Emperor, ROOT = Old Emperor
on_mandate_of_heaven_lost = {
	remove_government_reform = celestial_empire
	set_government_rank = 2
	add_country_modifier = {
		name = lost_mandate_of_heaven
		duration = 7300	# 20 years
	}
	add_stability = -2
	china_superregion = {
		limit = {
			is_permanent_claim = ROOT
		}
		remove_claim = ROOT
	}
	if = {
		limit = {
			has_country_modifier = new_mandate_holder
		}
		remove_country_modifier = new_mandate_holder
	}
}

on_embrace_revolution = {
	if = {	
		limit = {
			any_subject_country = {
				has_country_modifier = colony_inspired_by_revolution
			}
		}
		every_subject_country = {
			remove_country_modifier = colony_inspired_by_revolution
		}
	}
	if = {
		limit = { NOT = { government = republic } }
		change_government_to_republic = yes
	}
	if = {
		limit = { 
			revolution_target_exists = no
			is_great_power = yes
		}
		set_revolution_target = ROOT
		add_government_reform = revolutionary_republic_reform
		if = {
			limit = {
				any_country = {
					has_country_flag = last_revolutionary_country
				}
			}
			every_country = {
				limit = {
					has_country_flag = last_revolutionary_country
				}
				clr_country_flag = last_revolutionary_country
			}
		}
	}
	else = {
		add_government_reform = junior_revolutionary_republic_reform
	}
	if = {
		limit = { has_reform = parliamentary_reform }
		remove_government_reform = parliamentary_reform
	}
	kill_ruler = yes
	set_country_flag = revolutionary_republic_flag
	set_country_flag = had_revolution
}

# THIS = Revolutionary country being beaten, FROM = Country enforcing the peace treaty
on_dismantle_revolution = {
	events = {
		center_of_revolution.1500
	}
	if = {
		limit = {
			any_country = {
				has_country_flag = last_revolutionary_country
			}
		}
		every_country = {
			limit = {
				has_country_flag = last_revolutionary_country
			}
			clr_country_flag = last_revolutionary_country
		}
	}
	set_country_flag = last_revolutionary_country
}

# province
on_adm_development = {
}

# province
on_dip_development = {
}

# province
on_mil_development = {
}

on_overextension_pulse = {
	random_events = {
		100 = overextension.1
		100 = overextension.2
		100 = overextension.3
		100 = overextension.4
		100 = overextension.5
		100 = overextension.6
		100 = overextension.7
		100 = overextension.8
		100 = overextension.9
		100 = overextension.10
	}
}


on_colonial_pulse = {
	random_events = {
		100 = colonial.1
		100 = colonial.2
		100 = colonial.3
		100 = colonial.4
		100 = colonial.5
		100 = colonial.8
		100 = colonial.9
		100 = colonial.10
		100 = colonial.11
		100 = colonial.12
		100 = colonial.13
		100 = colonial.14
		100 = colonial.15
		100 = colonial.16
		100 = colonial.17
		100 = colonial.18
		25 = dodo.1

		15000 = 0
	}
}

on_siberian_pulse = {
}


# country random events
on_bi_yearly_pulse = {
	events = {
		center_of_revolution.2950
		center_of_revolution.3000
	}
	random_events = {
		# randomevents.txt
		100 = 3051
		100 = 5008
		100 = 5014
		100 = 5015
		100 = 5017
		100 = 5018
		100 = 5019
		100 = 5020
		100 = 5021
		100 = 5022
		100 = 5023
		100 = 5024
		100 = 5025
		100 = 5027
		100 = 5032
		100 = 5040
		100 = 5045
		100 = 5050
		100 = 5051
		100 = 5052
		100 = 5053
		10 = 5054
		100 = 5055
		100 = 5056
		100 = 5058
		100 = 5059
		100 = 5060
		100 = 5061
		100 = 5064
		100 = 5065
		100 = 5066
		100 = 5068
		100 = 5070
		100 = 5071
		100 = 5072
		100 = 5074
		100 = 5075
		100 = 5076
		100 = 5077
		100 = 5082
		100 = 5083
		100 = 5084
		100 = 5085
		100 = 5086
		100 = 5088
		100 = 5089
		100 = 5090
		100 = 5091
		100 = 5092
		100 = 5093
		100 = 5094
		100 = 5095
		10 = 5096
		100 = 5097
		100 = 5098
		100 = 5099
		100 = 6000
		100 = 6001
		100 = 6003
		100 = 6004
		100 = 6005
		100 = 6006
		100 = 6012
		100 = 6013
		100 = 6015
		100 = 710
		100 = 711
		100 = 712
		100 = 713
		100 = 714
		100 = 715
		100 = 716
		100 = 717
		100 = 718
		100 = 719
		100 = 720
		100 = 722
		100 = 723
		100 = 724
		100 = 725
		100 = 726
		100 = 727
		100 = 728
		100 = 729

		100 = random_event.1
		300 = random_event.2
		100 = random_event.3
		100 = random_event.4
		100 = random_event.5
		100 = random_event.6
		100 = random_event.7
		100 = random_event.8
		150 = random_event.9
		100 = random_event.10
		100 = random_event.11
		100 = random_event.12
		100 = random_event.13
		100 = random_event.14
		100 = random_event.15
		100 = random_event.16

		100 = random_event.26

		#Culture and Religion Events
		125 = culture_religion_events.1
		125 = culture_religion_events.3
		125 = culture_religion_events.4
		125 = culture_religion_events.5
		125 = culture_religion_events.6
		125 = culture_religion_events.7
		125 = culture_religion_events.8
		125 = culture_religion_events.9
		125 = culture_religion_events.10
		125 = culture_religion_events.11
		125 = culture_religion_events.12
		125 = culture_religion_events.13
		125 = culture_religion_events.14
		125 = culture_religion_events.15
		125 = culture_religion_events.16
		100 = culture_religion_events.17
		125 = culture_religion_events.18
		125 = culture_religion_events.19
		125 = culture_religion_events.20
		175 = culture_religion_events.21
		125 = culture_religion_events.22
		125 = culture_religion_events.23

		# Old Centralisation/Decentralisation
		100 = 806

		# Mercantilism
		100 = 6326
		100 = 6327
		100 = 6328
		100 = 6329

		# Trade Specific
		100 = trade.1
		100 = trade.2
		100 = trade.3
		100 = trade.4
		100 = trade.5
		100 = trade.6
		100 = trade.7
		100 = trade.8
		100 = trade.9
		100 = trade.10
		100 = trade.11
		100 = trade.12


		# Tradegoods events
		100 = 6418
		100 = 6419
		100 = 6420
		100 = 6421
		100 = 6422
		100 = 6423
		100 = 6424
		100 = 6425
		100 = 6426
		100 = 6427
		100 = 6428
		100 = 6429
		100 = 6431
		100 = 6432
		100 = 6433
		100 = 6434

		# Refoms, when having parliaments.
		100 = reforms.1
		100 = reforms.2
		100 = reforms.3
		100 = reforms.4

		100 = randomeventsstapehordes.1
		100 = randomeventsstapehordes.2
		100 = randomeventsstapehordes.3
		100 = randomeventsstapehordes.4
		100 = randomeventsstapehordes.5
		100 = randomeventsstapehordes.6
		100 = randomeventsstapehordes.7
		100 = randomeventsstapehordes.8
		100 = randomeventsstapehordes.13
		100 = randomeventsstapehordes.14
		100 = randomeventsstapehordes.17
		100 = randomeventsstapehordes.19
		100 = randomeventsstapehordes.20
		100 = randomeventsstapehordes.21
		100 = randomeventsstapehordes.22
		100 = randomeventsstapehordes.23
		100 = randomeventsstapehordes.24

		# Sailor events
		100 = sailor_event.1
		100 = sailor_event.2
		100 = sailor_event.3
		100 = sailor_event.4
		100 = sailor_event.5

		# Corruption Events
		100 = corruption_event.16
		100 = corruption_event.17
		100 = corruption_event.18
		100 = corruption_event.19
		100 = corruption_event.20


		# Institution Events
		#Feudalism Spread Events:
		150 = institution_events.8
		150 = institution_events.9
		150 = institution_events.10
		150 = institution_events.11
		#Global Trade Spread Events:
		150 = institution_events.50
		150 = institution_events.51
		150 = institution_events.52
		#Enlightenment Spread Events:
		150 = institution_events.70
		150 = institution_events.71
		150 = institution_events.72


		#Personality Events
		50 = personality_events.10 #Just Dilema
		50 = personality_events.11 #A righteous King
		50 = personality_events.12 #A Righteous Republican Ruler
		50 = personality_events.13
		50 = personality_events.14
		50 = personality_events.15
		50 = personality_events.16
		50 = personality_events.17
		50 = personality_events.18
		50 = personality_events.19
		50 = personality_events.20
		50 = personality_events.21
		50 = personality_events.22
		50 = personality_events.23
		50 = personality_events.24
		50 = personality_events.25
		50 = personality_events.26
		50 = personality_events.27
		50 = personality_events.28
		50 = personality_events.29
		50 = personality_events.30
		50 = personality_events.31
		50 = personality_events.32
		50 = personality_events.33
		50 = personality_events.34
		50 = personality_events.35
		50 = personality_events.36
		50 = personality_events.37
		50 = personality_events.38
		50 = personality_events.39
		50 = personality_events.40
		50 = personality_events.41
		50 = personality_events.42
		50 = personality_events.43
		50 = personality_events.44
		50 = personality_events.45
		50 = personality_events.46
		50 = personality_events.47
		50 = personality_events.48
		50 = personality_events.49
		50 = personality_events.50
		50 = personality_events.51
		50 = personality_events.52
		50 = personality_events.53
		50 = personality_events.54
		50 = personality_events.55
		50 = personality_events.56
		50 = personality_events.57
		50 = personality_events.58

		# Trade League Events
		100 = trade_league.1
		100 = trade_league.2
		100 = trade_league.3
		100 = trade_league.4
		100 = trade_league.7
		100 = trade_league.8
		100 = trade_league.9
		100 = trade_league.10
		100 = trade_league.11
		100 = trade_league.12
		100 = trade_league.13
		100 = trade_league.14

		#Industrial Revolution

		200 = industrialization_events.7
		200 = industrialization_events.8
		200 = industrialization_events.9
		200 = industrialization_events.10
		200 = industrialization_events.11
		200 = industrialization_events.12
		200 = industrialization_events.13
		200 = industrialization_events.14
		200 = industrialization_events.15
		200 = industrialization_events.16
		200 = industrialization_events.17
		200 = industrialization_events.18
		200 = industrialization_events.19
		200 = industrialization_events.20
		200 = industrialization_events.21
		200 = industrialization_events.22

		#Confucian Events
		75 = confucian_events.19
		75 = confucian_events.20

		# Orthodox Icon Events
		75 = orthodox_icon_events.1
		75 = orthodox_icon_events.3
		75 = orthodox_icon_events.4
		75 = orthodox_icon_events.5
		75 = orthodox_icon_events.6

		2000 = 0 #was 1250
	}
}

on_bi_yearly_pulse_2 = {
	random_events = {
		100 = corruption_event.1
		100 = corruption_event.2
		100 = corruption_event.3
		100 = corruption_event.4
		100 = corruption_event.5
		100 = corruption_event.6
		100 = corruption_event.7
		100 = corruption_event.8
		100 = corruption_event.9
		100 = corruption_event.10
		200 = corruption_event.11
		200 = corruption_event.12
		200 = corruption_event.13
		200 = corruption_event.14
		200 = corruption_event.15

		4000 = 0
	}
}

on_bi_yearly_pulse_3 = {

	#Fire estate agenda if you have that privilege
	# NOTE DOING THIS THROUGH RANDOM EVENT NOW WITH estate_privileges_and_agendas_events.4 INSTEAD!
	#on_bi_yearly_pulse_estate_privileges_effect = yes

	events = {
		muslim_school_events.20 #Pick School
	}
	random_events = {
		100 = new_court_flavour_events.21 #religious resignation
		100 = new_court_flavour_events.25 #blood is thicker than water
		200 = 0
	}
}

on_bi_yearly_pulse_4 = {
	random_events = { #all these were shifted from on_bi_yearly_pulse_1
		#randomevents
		100 = 730
		100 = 731
		100 = 732
		100 = 733
		100 = 734
		100 = 735
		100 = 736
		100 = 737
		100 = 738
		100 = 739
		100 = 740
		100 = 741
		100 = 742

		100 = 850
		100 = 851
		100 = 852
		100 = 853
		100 = 854
		100 = 855
		100 = 857
		100 = 858
		100 = 859
		100 = 860
		100 = 861
		100 = 862
		100 = 863
		100 = 864
		100 = 865
		100 = 866
		100 = 867
		100 = 868
		100 = 869
		100 = 870
		100 = 871
		100 = 872
		100 = 873
		100 = 874
		100 = 875
		100 = 876
		100 = 877
		100 = 878
		100 = 879
		100 = 880
		100 = 881
		100 = 882
		100 = 883
		100 = 884
		100 = 885
		100 = 836
		100 = 837
		100 = 838

		100 = 9472
		100 = 3097
		100 = 5005
		100 = 5026
		100 = 5037
		100 = 5063
		100 = 6014


		# Innovativeness
		100 = innovativeness_events.1
		100 = innovativeness_events.2
		50 = innovativeness_events.3
		100 = innovativeness_events.4
		100 = innovativeness_events.5
		100 = innovativeness_events.6
		100 = innovativeness_events.7
		100 = innovativeness_events.8
		100 = innovativeness_events.9
		100 = innovativeness_events.10
		100 = innovativeness_events.11
		100 = innovativeness_events.12
		100 = innovativeness_events.13
		100 = innovativeness_events.14
		100 = innovativeness_events.15

		# Trade Company Investments
		100 = investment_events.1
		100 = investment_events.2
		100 = investment_events.3
		100 = investment_events.4
		100 = investment_events.5
		100 = investment_events.6
		100 = investment_events.7
		100 = investment_events.8
		100 = investment_events.9
		100 = investment_events.10

		# Catholic Order Events
		100 = order_events.1
		100 = order_events.2
		100 = order_events.3
		100 = order_events.4
		100 = order_events.5
		100 = order_events.6
		100 = order_events.7
		100 = order_events.8
		100 = order_events.9

		# Minority Expulsion Events
		100 = expel_minority_events.1
		100 = expel_minority_events.2
		100 = expel_minority_events.3
		100 = expel_minority_events.4
		100 = expel_minority_events.5
		
		# Papal Tithe Events
		100 = curia.1
		100 = curia.2
		100 = curia.4
		100 = curia.9	
		100 = curia.10
		100 = curia.11
		100 = curia.12
		
		# Defender of the Faith
		100 = dotf.1
		100 = dotf.4
		100 = dotf.6
		100 = dotf.7
		
		# Mercenaries
		100 = mercs.1
		100 = mercs.2
		100 = mercs.3
		100 = mercs.4
		100 = mercs.7
		100 = mercs.7
		100 = mercs.8
		100 = mercs.10
		100 = mercs.11

		# Espionage
		100 = espionage_events.1
		100 = espionage_events.4
		100 = espionage_events.8
		80 = espionage_events.9

		#Reign of Terror
		150 = french_revolution.302
		100 = french_revolution.303
		
		# Papacy events
		100 = papacy_events.6

		# Professionalism
		100 = army_professionalism_events.4
		100 = army_professionalism_events.5
		75 = army_professionalism_events.6
		100 = army_professionalism_events.8
		100 = army_professionalism_events.9
		100 = army_professionalism_events.10
		100 = army_professionalism_events.11
		75 = army_professionalism_events.12
		100 = army_professionalism_events.13
		75 = army_professionalism_events.16

		# Agenda from the Estates
		1000 = estate_privileges_and_agendas_events.4
		1000 = estate_privileges_and_agendas_events.5

		2000 = 0
	}
}

on_bi_yearly_pulse_5 = {
	random_events = { #all these were shifted from on_bi_yearly_pulse_1
		# Anglican Events
		100 = anglican_events.1
		100 = anglican_events.2
		100 = anglican_events.3
		100 = anglican_events.4
		100 = anglican_events.5
		100 = anglican_events.6
		100 = anglican_events.7
		100 = anglican_events.8
		100 = anglican_events.9
		100 = anglican_events.10
		100 = anglican_events.11
		100 = anglican_events.12
		100 = anglican_events.13
		150 = anglican_events.15
		
		# Hussite Events
		100 = hussite.1
		100 = hussite.2
		100 = hussite.3
		100 = hussite.4
		100 = hussite.5
		100 = hussite.6
		100 = hussite.7


		#Mamluk Events

		175 = mamluk_events.1
		175 = mamluk_events.2
		175 = mamluk_events.3
		235 = mamluk_events.4
		185 = mamluk_events.5
		175 = mamluk_events.6
		250 = mamluk_events.7
		185 = mamluk_events.10
		185 = mamluk_events.11
		235 = mamluk_events.12

		#Colonization of Siberia
		125 = siberian_events.2
		125 = siberian_events.3
		125 = siberian_events.4
		125 = siberian_events.5
		125 = siberian_events.6

		#Russian Principalities

		100 = russian_principality_events.1
		125 = russian_principality_events.2
		125 = russian_principality_events.3
		125 = russian_principality_events.4
		125 = russian_principality_events.6
		125 = russian_principality_events.5
		125 = russian_principality_events.7
		100 = russian_principality_events.8
		75 = russian_principality_events.9
		125 = russian_principality_events.10

		#Tsardoms

		125 = russian_tsardom_events.1
		125 = russian_tsardom_events.2
		125 = russian_tsardom_events.3
		100 = russian_tsardom_events.4
		125 = russian_tsardom_events.5
		100 = russian_tsardom_events.6
		100 = russian_tsardom_events.7
		100 = russian_tsardom_events.8
		125 = russian_tsardom_events.9
		125 = russian_tsardom_events.10
		100 = russian_tsardom_events.11

		#Streltsy Events
		125 = streltsy_events.1
		125 = streltsy_events.3
		125 = streltsy_events.4
		125 = streltsy_events.5
		100 = streltsy_events.6

		#Orthodox Metropolitans
		125 = patriarch_events.1
		125 = patriarch_events.2
		125 = patriarch_events.3
		75 = patriarch_events.4
		75 = patriarch_events.5

		# Catholic  Events
		100 = catholic_flavor.4
		100 = catholic_flavor.5
		100 = catholic_flavor.6
		100 = catholic_flavor.7
		100 = catholic_flavor.8
		100 = catholic_flavor.9
		100 = catholic_flavor.10

		# Japanese Daimyos
		15 = flavor_jap.10
		50 = flavor_jap.28
		100 = flavor_jap.40
		100 = flavor_jap.42
		100 = flavor_jap.43
		100 = flavor_jap.45
		100 = flavor_jap.49
		100 = flavor_jap.51
		100 = flavor_jap.52
		100 = flavor_jap.53
		100 = flavor_jap.54
		100 = flavor_jap.55



		# China
		75 = meritocracy_events.1
		75 = meritocracy_events.2
		75 = meritocracy_events.3
		75 = meritocracy_events.4
		75 = meritocracy_events.5
		50 = china_events.11
		25 = china_events.12
		25 = china_events.24

		2000 = 0
	}
}



# country random events
on_thri_yearly_pulse = {
	random_events = {
		# Republics
		100 = republics.4
		100 = republics.5
		100 = republics.6
		100 = republics.7
		100 = republics.8
		100 = republics.9
		100 = republics.10
		100 = republics.11
		100 = republics.12
		100 = republics.13
		100 = republics.14
		100 = republics.15
		100 = republics.16
		100 = republics.17
		100 = republics.18
		100 = republics.19
		100 = republics.20
		100 = republics.21
		100 = republics.22
		100 = republics.23
		100 = republics.24
		100 = republics.25
		100 = republics.26
		100 = republics.27
		100 = republics.28
		100 = republics.29
		100 = republics.30
		100 = republics.31
		100 = republics.32
		100 = republics.33
		100 = republics.34
		100 = republics.35
		100 = republics.36
		100 = republics.37
		100 = republics.38
		100 = republics.39
		100 = republics.40
		100 = republics.41
		100 = republics.42
		100 = republics.43

		# Theocracies
		100 = devotion_events.1
		100 = devotion_events.2
		100 = devotion_events.3
		100 = devotion_events.4
		100 = devotion_events.5
		100 = devotion_events.6
		100 = devotion_events.7
		100 = devotion_events.8
		100 = devotion_events.9
		100 = devotion_events.10
		100 = devotion_events.11
		100 = devotion_events.12
		100 = devotion_events.13
		100 = devotion_events.14
		100 = devotion_events.15
		100 = devotion_events.16
		100 = devotion_events.18
		100 = devotion_events.19
		100 = devotion_events.22
		100 = devotion_events.23
		100 = devotion_events.24
		100 = devotion_events.26
		100 = devotion_events.100
		100 = devotion_events.101
		100 = devotion_events.102
		100 = devotion_events.104
		100 = devotion_events.107
		100 = devotion_events.110
		100 = devotion_events.117
		100 = devotion_events.118
		100 = devotion_events.119
		100 = devotion_events.200
		100 = devotion_events.201
		100 = devotion_events.202
		100 = devotion_events.203
		100 = devotion_events.204
		100 = devotion_events.205
		100 = devotion_events.207
		100 = devotion_events.208
		100 = devotion_events.209
		100 = devotion_events.210
		100 = devotion_events.211
		100 = devotion_events.212
		100 = devotion_events.213
		100 = devotion_events.214
		100 = devotion_events.215
		100 = devotion_events.216
		100 = devotion_events.217
		100 = devotion_events.218
		100 = devotion_events.219



		#Center of Revolution - post-spawn (higher weighting than others as they are only relevant briefly)
		200 = center_of_revolution.1
		150 = center_of_revolution.2
		200 = center_of_revolution.3
		200 = center_of_revolution.8
		250 = center_of_revolution.9
		250 = center_of_revolution.10
		200 = center_of_revolution.12
		#Center of Revolution - pre-spawn
		100 = center_of_revolution.2000
		100 = center_of_revolution.2002
		100 = center_of_revolution.2003
		100 = center_of_revolution.2010

		1000 = 0
	}
}

on_thri_yearly_pulse_2 = {
	random_events = {
		# Random to increase or decrease patriarch authority.
		25 = orthodox_flavor.1
		20 = orthodox_flavor.2
		25 = orthodox_flavor.3
		25 = orthodox_flavor.4
		25 = orthodox_flavor.5

		# Muslim Piety Events
		40 = muslim_piety.1
		40 = muslim_piety.2
		40 = muslim_piety.3
		20 = muslim_piety.4
		20 = muslim_piety.5
		40 = muslim_piety.6
		40 = muslim_piety.7
		40 = muslim_piety.8
		40 = muslim_piety.9
		40 = muslim_piety.10
		40 = muslim_piety.11
		40 = muslim_piety.12
		40 = muslim_piety.13
		40 = muslim_piety.14
		40 = muslim_piety.15
		40 = muslim_piety.16
		40 = muslim_piety.22
		300 = 0
	}
}

on_thri_yearly_pulse_3 = {
	random_events = {
		# Subject Interactions
		50 = subject_interaction_events.1
		50 = subject_interaction_events.4
		50 = subject_interaction_events.5
		50 = subject_interaction_events.6
		50 = subject_interaction_events.7
		50 = subject_interaction_events.9
		50 = subject_interaction_events.11
		50 = subject_interaction_events.14
		50 = subject_interaction_events.15
		50 = subject_interaction_events.17
		50 = subject_interaction_events.18
		50 = subject_interaction_events.19
		50 = subject_interaction_events.20
		50 = subject_interaction_events.21
		50 = subject_interaction_events.22
		50 = subject_interaction_events.23
		50 = subject_interaction_events.24
		50 = subject_interaction_events.25
		50 = subject_interaction_events.26
		50 = subject_interaction_events.27
		50 = subject_interaction_events.29
		50 = subject_interaction_events.30
		50 = subject_interaction_events.31
		50 = subject_interaction_events.32
		50 = subject_interaction_events.34
		50 = subject_interaction_events.35
		50 = subject_interaction_events.36
		50 = subject_interaction_events.38
		50 = subject_interaction_events.40
		50 = subject_interaction_events.43
		75 = tributary_events.1
		75 = tributary_events.2
		75 = tributary_events.3
		75 = tributary_events.4
		75 = tributary_events.5
		75 = tributary_events.6
		75 = tributary_events.7
		75 = tributary_events.8
		75 = tributary_events.9
		75 = tributary_events.10
		75 = tributary_events.13
		75 = tributary_events.16
		75 = tributary_events.17
		75 = tributary_events.18
		75 = tributary_events.19
		75 = tributary_events.23
		75 = tributary_events.24
		75 = tributary_events.26
		75 = tributary_events.25
		75 = tributary_events.27

		1000 = 0
	}
}

on_thri_yearly_pulse_4 = {
	random_events = {
		#Low Mandate Events
		10 = china_events.45
		10 = china_events.46
		50 = china_events.47
		10 = china_events.48
		10 = china_events.49
		10 = china_events.50
		50 = china_events.51
		10 = china_events.52
		10 = china_events.53
		50 = china_events.54
		#10 = china_events.55 (triggers via neighbors)
		10 = china_events.56
		75 = china_events.57
		50 = china_events.58
		10 = china_events.59
		50 = china_events.60
	}
}

on_four_year_pulse = {
	random_events = {
		# Colonial Nations
		100 = colonial_nation.1
		100 = colonial_nation.4
		100 = colonial_nation.10
		100 = colonial_nation.12
		100 = colonial_nation.14
		100 = colonial_nation.77
		100 = colonial_nation.100
		100 = colonial_nation.102
		100 = colonial_nation.104
		100 = colonial_nation.106
		100 = colonial_nation.108
		100 = colonial_nation.110
		100 = colonial_nation.112
		100 = colonial_nation.114
		100 = colonial_nation.116
		100 = colonial_nation.118
		100 = colonial_nation.120
		100 = colonial_nation.122
		100 = colonial_nation.124
		100 = colonial_nation.126
		100 = colonial_nation.128
		100 = colonial_nation.130
		100 = colonial_nation.132
		100 = colonial_nation.134
		100 = colonial_nation.182
		100 = colonial_nation.183
		100 = colonial_nation.184
		100 = colonial_nation.185
		100 = colonial_nation.186
		100 = colonial_nation.187
		100 = colonial_nation.188
		100 = colonial_nation.189
		10 = colonial_nation.140
		10 = colonial_nation.142
		10 = colonial_nation.144
		10 = colonial_nation.146
		10 = colonial_nation.148
		10 = colonial_nation.150
		10 = colonial_nation.152
		10 = colonial_nation.154
		10 = colonial_nation.156
		10 = colonial_nation.158
		10 = colonial_nation.160
		10 = colonial_nation.162
		10 = colonial_nation.164
		10 = colonial_nation.166
		10 = colonial_nation.168
		10 = colonial_nation.170
		10 = colonial_nation.172
		10 = colonial_nation.174
		10 = colonial_nation.176

		# Dutch Republic
		100 = dutch_republic.1
		100 = dutch_republic.2
		100 = dutch_republic.3
		100 = dutch_republic.4
		100 = dutch_republic.5
		100 = dutch_republic.6
		100 = dutch_republic.7
		100 = dutch_republic.8
		100 = dutch_republic.9
		100 = dutch_republic.10
		150 = dutch_republic.11
		100 = dutch_republic.13
		100 = dutch_republic.14
		100 = dutch_republic.15
		100 = dutch_republic.16
		100 = dutch_republic.17
		100 = dutch_republic.18
		100 = dutch_republic.19
		100 = dutch_republic.20
		100 = dutch_republic.21
		100 = dutch_republic.22
		100 = dutch_republic.23
		100 = dutch_republic.24
		100 = dutch_republic.25
		100 = dutch_republic.27

		# Republic Factions
		100 = republic_factions.2
		100 = republic_factions.5
		100 = republic_factions.7
		100 = republic_factions.9
		100 = republic_factions.10
		100 = republic_factions.12
		100 = republic_factions.13
		100 = republic_factions.14
		100 = republic_factions.15
		100 = republic_factions.16
		100 = republic_factions.17
		100 = republic_factions.18
		100 = republic_factions.19
		100 = republic_factions.20
		100 = republic_factions.22
		100 = republic_factions.23
		100 = republic_factions.24

		# Revolutionary Republic Factions

		100 = revolutionary_republic_factions.0
		100 = revolutionary_republic_factions.1
		100 = revolutionary_republic_factions.2
		100 = revolutionary_republic_factions.3
		100 = revolutionary_republic_factions.4
		100 = revolutionary_republic_factions.5
		100 = revolutionary_republic_factions.6
		100 = revolutionary_republic_factions.7
		100 = revolutionary_republic_factions.8
		100 = revolutionary_republic_factions.9
		
		# Revolutionary Empires
		100 = napoleon.1
		100 = napoleon.2

		# Pirate Factions
		100 = pirates.10
		100 = pirates.11
		100 = pirates.12
		100 = pirates.13
		100 = pirates.14
		100 = pirates.15
		100 = pirates.16
		100 = pirates.17
		100 = pirates.18
		100 = pirates.19

		# Republican Dictatorship
		100 = republican_dictatorship.1
		100 = republican_dictatorship.2
		100 = republican_dictatorship.3
		100 = republican_dictatorship.4
		100 = republican_dictatorship.5
		100 = republican_dictatorship.6
		100 = republican_dictatorship.7
		100 = republican_dictatorship.8

		# Elective Monarchy
		150 = elective_monarchy.1
		150 = elective_monarchy.2
		25 = elective_monarchy.3
		25 = elective_monarchy.4
		150 = elective_monarchy.6
		150 = elective_monarchy.8
		150 = elective_monarchy.9
		150 = elective_monarchy.10
		150 = elective_monarchy.11
		150 = elective_monarchy.12
		150 = elective_monarchy.14
		150 = elective_monarchy.17
		25 = elective_monarchy.18

		# Free Cities
		25 = free_cities.3
		25 = free_cities.8
		25 = free_cities.10
		25 = free_cities.13
		25 = free_cities.17
		25 = free_cities.19

		#Tribal Federations
		50 = tribal_federation_events.1
		50 = tribal_federation_events.2
		50 = tribal_federation_events.3
		50 = tribal_federation_events.4
		50 = tribal_federation_events.5
		50 = tribal_federation_events.6
		50 = tribal_federation_events.7
		50 = tribal_federation_events.8
		50 = tribal_federation_events.10

		#Empire of China
		100 = china_events.1
		100 = china_events.2
		100 = china_events.3
		100 = china_events.4
		75 = china_events.5
		100 = china_events.6
		100 = china_events.7
		100 = china_events.8
		100 = china_events.9
		100 = china_events.10
		100 = china_events.11
		100 = china_events.12
		100 = china_events.13
		100 = china_events.14
		100 = china_events.15
		100 = china_events.16
		100 = china_events.17
		100 = china_events.18
		100 = china_events.19
		100 = china_events.20
		100 = china_events.21
		100 = china_events.22
		100 = china_events.23
		100 = china_events.24
		100 = china_events.25
		100 = china_events.26
		100 = china_events.27
		100 = china_events.28
		100 = china_events.29
		100 = china_events.30
		100 = china_events.33
		100 = china_events.34
		100 = china_events.35
		100 = china_events.36
		100 = china_events.37
		100 = china_events.38
		100 = china_events.39
		50 = china_events.40
		100 = china_events.41
		100 = china_events.42
		100 = china_events.44

		10 = tortoise.1 # Galapagos Island Tortoises
		
		100 = flavor_pue.5
		
		#Totemism Events
		100 = totemism_flavor.1
		100 = totemism_flavor.7
		100 = totemism_flavor.8
		100 = totemism_flavor.10
		100 = totemism_flavor.11
		100 = totemism_flavor.13
		100 = totemism_flavor.14
		100 = totemism_flavor.15
		100 = totemism_flavor.16
		100 = totemism_flavor.17
		100 = totemism_flavor.18
		
		#Volcano Events
		75 = volcano_events.2

		1000 = 0
	}
}

on_four_year_pulse_2 = {
}

on_four_year_pulse_3 = {
}

on_four_year_pulse_4 = {
}

on_five_year_pulse = {
	random_events = {

		# Innovativeness Events

		100 = innovativeness_events.1

		# Aristocracy 		13  (8g 5b)
		100 = ideagroups.100
		100 = ideagroups.101
		100 = ideagroups.102
		100 = ideagroups.103
		100 = ideagroups.104
		100 = ideagroups.105
		100 = ideagroups.106
		100 = ideagroups.107
		100 = ideagroups.108
		100 = ideagroups.109
		100 = ideagroups.110
		100 = ideagroups.111
		100 = ideagroups.112


		# Plutocracy 		19 (12g 7b)
		100 = ideagroups.200
		100 = ideagroups.201
		100 = ideagroups.202
		100 = ideagroups.203
		100 = ideagroups.204
		100 = ideagroups.205
		100 = ideagroups.206
		100 = ideagroups.207
		100 = ideagroups.208
		100 = ideagroups.209
		100 = ideagroups.210
		100 = ideagroups.211
		100 = ideagroups.212
		100 = ideagroups.213
		100 = ideagroups.214
		100 = ideagroups.215
		100 = ideagroups.216
		100 = ideagroups.217
		100 = ideagroups.218

		# Innovativenes		11 (7g 4b)
		100 = ideagroups.300
		100 = ideagroups.301
		100 = ideagroups.302
		100 = ideagroups.303
		100 = ideagroups.304
		100 = ideagroups.305
		100 = ideagroups.306
		100 = ideagroups.307
		100 = ideagroups.308
		100 = ideagroups.309
		100 = ideagroups.310

		# Religious		18 (11g 7b)
		100 = ideagroups.400
		100 = ideagroups.401
		100 = ideagroups.402
		100 = ideagroups.403
		100 = ideagroups.404
		100 = ideagroups.405
		100 = ideagroups.406
		100 = ideagroups.407
		100 = ideagroups.408
		100 = ideagroups.409
		100 = ideagroups.410
		100 = ideagroups.411
		100 = ideagroups.412
		100 = ideagroups.413
		100 = ideagroups.414
		100 = ideagroups.415
		100 = ideagroups.416
		100 = ideagroups.417


		# Spy			9 (6g 3b)
		100 = ideagroups.500
		100 = ideagroups.501
		100 = ideagroups.502
		100 = ideagroups.503
		100 = ideagroups.504
		100 = ideagroups.505
		100 = ideagroups.506
		100 = ideagroups.507
		100 = ideagroups.508


		# Diplomatic		9 (6g 3b)
		100 = ideagroups.600
		100 = ideagroups.601
		100 = ideagroups.602
		100 = ideagroups.603
		100 = ideagroups.604
		100 = ideagroups.605
		100 = ideagroups.606
		100 = ideagroups.607
		100 = ideagroups.608


		# Offensive 		14 (9g 5b)
		100 = ideagroups.700
		100 = ideagroups.701
		100 = ideagroups.702
		100 = ideagroups.703
		100 = ideagroups.704
		100 = ideagroups.705
		100 = ideagroups.706
		100 = ideagroups.707
		100 = ideagroups.708
		100 = ideagroups.709
		100 = ideagroups.710
		100 = ideagroups.711
		100 = ideagroups.712
		100 = ideagroups.713


		# Defensive		11 (5g 6b)
		100 = ideagroups.800
		100 = ideagroups.801
		100 = ideagroups.802
		100 = ideagroups.803
		100 = ideagroups.804
		100 = ideagroups.805
		100 = ideagroups.806
		100 = ideagroups.807
		100 = ideagroups.808
		100 = ideagroups.809
		100 = ideagroups.810
		100 = ideagroups.811
		100 = ideagroups.812
		100 = ideagroups.813
		100 = ideagroups.814
		100 = ideagroups.815


		# Trade			6 (7g 4b)
		100 = ideagroups.900
		100 = ideagroups.901
		100 = ideagroups.902
		100 = ideagroups.903
		100 = ideagroups.904
		100 = ideagroups.905
		100 = ideagroups.906
		100 = ideagroups.907
		100 = ideagroups.908
		100 = ideagroups.909
		100 = ideagroups.910

		# Maritime			22 (14g 8b)
		100 = ideagroups.1000
		100 = ideagroups.1001
		100 = ideagroups.1002
		100 = ideagroups.1003
		100 = ideagroups.1004
		100 = ideagroups.1005
		100 = ideagroups.1006
		100 = ideagroups.1007
		100 = ideagroups.1008
		100 = ideagroups.1009
		100 = ideagroups.1010
		100 = ideagroups.1011
		100 = ideagroups.1012
		100 = ideagroups.1013
		100 = ideagroups.1014
		100 = ideagroups.1015
		100 = ideagroups.1016
		100 = ideagroups.1017
		100 = ideagroups.1018
		100 = ideagroups.1019
		100 = ideagroups.1020
		100 = ideagroups.1021

		# Economic		11 (7g 4b)
		100 = ideagroups.1100
		100 = ideagroups.1101
		100 = ideagroups.1102
		100 = ideagroups.1103
		100 = ideagroups.1104
		100 = ideagroups.1105
		100 = ideagroups.1106
		100 = ideagroups.1107
		100 = ideagroups.1108
		100 = ideagroups.1109
		100 = ideagroups.1110

		# Exploration		11 (7g 4b)
		100 = ideagroups.1200
		100 = ideagroups.1201
		100 = ideagroups.1202
		100 = ideagroups.1203
		100 = ideagroups.1204
		100 = ideagroups.1205
		100 = ideagroups.1206
		100 = ideagroups.1207
		100 = ideagroups.1208
		100 = ideagroups.1209
		100 = ideagroups.1210

		# Quality		11 (7g 4b)
		100 = ideagroups.1300
		100 = ideagroups.1301
		100 = ideagroups.1302
		100 = ideagroups.1303
		100 = ideagroups.1304
		100 = ideagroups.1305
		100 = ideagroups.1306
		100 = ideagroups.1307
		100 = ideagroups.1308
		100 = ideagroups.1309
		100 = ideagroups.1310

		# Quantity		11 (7g 4b)
		100 = ideagroups.1400
		100 = ideagroups.1401
		100 = ideagroups.1402
		100 = ideagroups.1403
		100 = ideagroups.1404
		100 = ideagroups.1405
		100 = ideagroups.1406
		100 = ideagroups.1407
		100 = ideagroups.1408
		100 = ideagroups.1409
		100 = ideagroups.1410


		# Expansion		11 (7g 4b)
		100 = ideagroups.1500
		100 = ideagroups.1501
		100 = ideagroups.1502
		100 = ideagroups.1503
		100 = ideagroups.1504
		100 = ideagroups.1505
		100 = ideagroups.1506
		100 = ideagroups.1507
		100 = ideagroups.1508
		100 = ideagroups.1509
		100 = ideagroups.1510

		# Administrative	3 (1g 2b)
		100 = ideagroups.1600
		100 = ideagroups.1601
		100 = ideagroups.1602
		100 = ideagroups.1603
		100 = ideagroups.1604
		100 = ideagroups.1605
		100 = ideagroups.1606
		100 = ideagroups.1607
		100 = ideagroups.1608
		100 = ideagroups.1609
		100 = ideagroups.1610

		# Naval		11 (7g 4b)
		100 = ideagroups.1700
		100 = ideagroups.1701
		100 = ideagroups.1702
		100 = ideagroups.1703
		100 = ideagroups.1704
		100 = ideagroups.1705
		100 = ideagroups.1706
		100 = ideagroups.1707
		100 = ideagroups.1708
		100 = ideagroups.1709
		100 = ideagroups.1710

		# Influence		11 (7g 4b)
		100 = ideagroups.1800
		100 = ideagroups.1801
		100 = ideagroups.1802
		100 = ideagroups.1803
		100 = ideagroups.1804
		100 = ideagroups.1805
		100 = ideagroups.1806
		100 = ideagroups.1807
		100 = ideagroups.1808
		100 = ideagroups.1809
		100 = ideagroups.1810

		# Humanist		11 (7g 4b)
		100 = ideagroups.1900
		100 = ideagroups.1901
		100 = ideagroups.1902
		100 = ideagroups.1903
		100 = ideagroups.1904
		100 = ideagroups.1905
		100 = ideagroups.1906
		100 = ideagroups.1907
		100 = ideagroups.1908
		100 = ideagroups.1909
		100 = ideagroups.1910

		# Horde Ideas		10 (8g 2b)
		100 = ideagroups.1922
		100 = ideagroups.1923
		100 = ideagroups.1924
		100 = ideagroups.1925
		100 = ideagroups.1926
		100 = ideagroups.1927
		100 = ideagroups.1928
		100 = ideagroups.1929
		100 = ideagroups.1930
		100 = ideagroups.1931
		
		#Theocracy Ideas		11 (9g 2b)
		100 = ideagroups.1911
		100 = ideagroups.1912
		100 = ideagroups.1913
		100 = ideagroups.1914
		100 = ideagroups.1915
		100 = ideagroups.1916
		100 = ideagroups.1917
		100 = ideagroups.1918
		100 = ideagroups.1919
		100 = ideagroups.1920
		100 = ideagroups.1921

		# Indigenous		10 (6g 4b)
		100 = ideagroups.1932
		100 = ideagroups.1933
		100 = ideagroups.1934
		100 = ideagroups.1935
		100 = ideagroups.1936
		100 = ideagroups.1937
		100 = ideagroups.1938
		100 = ideagroups.1939
		100 = ideagroups.1940
		100 = ideagroups.1941
		
		1000 = 0
	}

	events = {
		seven_cities_events.1000 #Clearing of Seven Cities Hunt when goal is no longer possible
	}
}


# Estates pulse
on_five_year_pulse_2 = {
	random_events = {
		# Burghers
		100 = burghers_estate_events.1
		100 = burghers_estate_events.2
		100 = burghers_estate_events.3
		100 = burghers_estate_events.4
		100 = burghers_estate_events.5
		100 = burghers_estate_events.6
		100 = burghers_estate_events.7
		100 = burghers_estate_events.8
		100 = burghers_estate_events.9
		400 = burghers_estate_events.10 #Demands
		100 = burghers_estate_events.11 #Bonus
		100 = burghers_estate_events.12
		100 = burghers_estate_events.13
		400 = burghers_estate_events.14 #Demands
		100 = burghers_estate_events.15 #Disloyal
		# Nobles
		100 = nobles_estate_events.1 #Demands
		100 = nobles_estate_events.2
		100 = nobles_estate_events.3
		100 = nobles_estate_events.4
		400 = nobles_estate_events.5 #Demands
		100 = nobles_estate_events.6
		100 = nobles_estate_events.7
		400 = nobles_estate_events.8 #Disloyal
		400 = nobles_estate_events.9 #Disloyal
		50 = nobles_estate_events.10
		100 = nobles_estate_events.11 #Bonus
		# Clergy
		100 = church_estate_events.1
			#Regional Variations:
			100 = church_estate_events.101
			100 = church_estate_events.102
			100 = church_estate_events.103
			100 = church_estate_events.104
			100 = church_estate_events.105
		100 = church_estate_events.2
		100 = church_estate_events.3
		100 = church_estate_events.4
		400 = church_estate_events.5 #Disloyal
		400 = church_estate_events.6 #Demands
		100 = church_estate_events.7 #Bonus
		100 = church_estate_events.8
		100 = church_estate_events.9
		100 = church_estate_events.10
		# Dhimmi
		100 = dhimmi_estate_events.1
		400 = dhimmi_estate_events.2 #Demands
		100 = dhimmi_estate_events.3
		100 = dhimmi_estate_events.4
		100 = dhimmi_estate_events.5
		100 = dhimmi_estate_events.6
		400 = dhimmi_estate_events.7 #Disloyal
		100 = dhimmi_estate_events.8
		# Cossacks
		100 = cossack_estate_events.1
		#100 = cossack_estate_events.2 (triggers in neighbor country)
		100 = cossack_estate_events.6
		100 = cossack_estate_events.7
		100 = cossack_estate_events.8
		100 = cossack_estate_events.9
		100 = cossack_estate_events.10
		100 = cossack_estate_events.11
		400 = cossack_estate_events.12 #Disloyal
		100 = cossack_estate_events.13
		400 = cossack_estate_events.14 #Demands
		# Tribes
		100 = tribal_estate_events.1
		100 = tribal_estate_events.2
		100 = tribal_estate_events.3
		100 = tribal_estate_events.4
		100 = tribal_estate_events.5
		100 = tribal_estate_events.6
		100 = tribal_estate_events.7
		100 = tribal_estate_events.8
		100 = tribal_estate_events.9
		150 = tribal_estate_events.11 #Demands
		150 = tribal_estate_events.12 #Demands
		150 = tribal_estate_events.13 #Demands
		150 = tribal_estate_events.14 #Demands
		# Marathas
		100 = marathas_estate_events.2
		100 = marathas_estate_events.3
		100 = marathas_estate_events.4
		100 = marathas_estate_events.5
		100 = marathas_estate_events.6
		400 = marathas_estate_events.7 # Demands
		100 = marathas_estate_events.8
		100 = marathas_estate_events.9
		100 = marathas_estate_events.10
		400 = marathas_estate_events.11 # Disloyal
		# Brahmins
		400 = brahmins_estate_events.2 # demands
		100 = brahmins_estate_events.3
		100 = brahmins_estate_events.4
		100 = brahmins_estate_events.5
		400 = brahmins_estate_events.6 # disloyal
		100 = brahmins_estate_events.7
		100 = brahmins_estate_events.8
		100 = brahmins_estate_events.9
		100 = brahmins_estate_events.10
		100 = brahmins_estate_events.11
		# Jains
		100 = jains_estate_events.2
		100 = jains_estate_events.3
		100 = jains_estate_events.4
		100 = jains_estate_events.5
		100 = jains_estate_events.6
		100 = jains_estate_events.7
		400 = jains_estate_events.8 # Disloyal
		100 = jains_estate_events.9
		400 = jains_estate_events.10 # Demands
		100 = jains_estate_events.11
		# Vaishyas
		100 = vaisyas_estate_events.2
		100 = vaisyas_estate_events.3
		100 = vaisyas_estate_events.4
		100 = vaisyas_estate_events.5
		100 = vaisyas_estate_events.6
		100 = vaisyas_estate_events.7
		100 = vaisyas_estate_events.8
		400 = vaisyas_estate_events.9
		100 = vaisyas_estate_events.10
		100 = vaisyas_estate_events.11
		# Rajputs
		100 = rajputs_estate_events.2
		100 = rajputs_estate_events.3
		100 = rajputs_estate_events.4
		100 = rajputs_estate_events.5
		400 = rajputs_estate_events.6
		100 = rajputs_estate_events.7
		400 = rajputs_estate_events.8
		100 = rajputs_estate_events.9
		100 = rajputs_estate_events.10
		100 = rajputs_estate_events.11
		# Random
		5 = flavor_fra.9500
		1000 = 0
	}
}

on_five_year_pulse_3 = {
	random_events = {
		100 = propagate_religion_events.1
		100 = propagate_religion_events.2
		100 = propagate_religion_events.3
		100 = propagate_religion_events.4
		100 = propagate_religion_events.5
		100 = propagate_religion_events.6
		100 = propagate_religion_events.8
		100 = propagate_religion_events.9
		100 = propagate_religion_events.10
		#100 = propagate_religion_events.11 #Province event
		1000 = 0
	}
}

on_five_year_pulse_4 = {
	if = { #fail-safe for flavor_pap.7, making religious leagues happen at some point if there is no PAP
		limit = {
			is_year = 1610
			NOT = { exists = PAP }
			NOT = { has_global_flag = counter_reformation }
		}
		set_global_flag = counter_reformation
	}
	#fail-safe if for whatever reason these flags stay after being used in events
	if = {
		limit = {
			had_country_flag = {
				flag = advisor_events_adm
				days = 720
			}
		}
		clr_country_flag = advisor_events_adm
	}
	if = {
		limit = {
			had_country_flag = {
				flag = advisor_events_dip
				days = 720
			}
		}
		clr_country_flag = advisor_events_dip
	}
	if = {
		limit = {
			had_country_flag = {
				flag = advisor_events_mil
				days = 720
			}
		}
		clr_country_flag = advisor_events_mil
	}
	#Clearing of Jewish events flags
	if = {
		limit = {
			had_country_flag = {
				flag = shalosh_regalim
				days = 365
			}
		}
		clr_country_flag = shalosh_regalim
	}
}

# El Dorado
on_explore_coast = {
	random_events = {
		10 = exploration_events.1
		10 = exploration_events.2
		10 = exploration_events.3
		10 = exploration_events.4
		10 = exploration_events.5
		10 = exploration_events.6
		10 = exploration_events.7
		10 = exploration_events.8
		10 = exploration_events.9
		10 = exploration_events.10
		10 = exploration_events.11
		10 = exploration_events.12
		10 = exploration_events.13
		10 = exploration_events.14
		10 = exploration_events.15
	}
}
on_conquistador_empty = {
	random_events = {
		10 = seven_cities_events.1
		10 = seven_cities_events.2
		10 = seven_cities_events.3
		10 = seven_cities_events.4
		10 = seven_cities_events.5
		10 = seven_cities_events.6
		10 = seven_cities_events.7
		10 = seven_cities_events.8

		10 = seven_cities_events.100
		10 = seven_cities_events.101
		10 = seven_cities_events.102
		10 = seven_cities_events.103
		10 = seven_cities_events.104
		10 = seven_cities_events.105

		50 = seven_cities_events.200
		50 = seven_cities_events.201
		50 = seven_cities_events.202
		50 = seven_cities_events.203
		50 = seven_cities_events.204
		50 = seven_cities_events.205
		50 = seven_cities_events.206
		50 = seven_cities_events.207
		50 = seven_cities_events.208
		50 = seven_cities_events.209
		50 = seven_cities_events.210
		50 = seven_cities_events.211
		50 = seven_cities_events.212
		50 = seven_cities_events.213
		50 = seven_cities_events.214
		50 = seven_cities_events.215
		50 = seven_cities_events.216
		50 = seven_cities_events.217
		50 = seven_cities_events.218
		50 = seven_cities_events.219
		50 = seven_cities_events.220
		50 = seven_cities_events.221
		50 = seven_cities_events.222
		50 = seven_cities_events.223

		10 = seven_cities_events.302
		10 = seven_cities_events.303
		10 = seven_cities_events.308
		10 = seven_cities_events.309

		10 = seven_cities_events.400
		10 = seven_cities_events.401
		10 = seven_cities_events.402
		10 = seven_cities_events.405
		10 = seven_cities_events.406
		10 = seven_cities_events.407
		10 = seven_cities_events.408
		10 = seven_cities_events.409
		10 = seven_cities_events.410
		10 = seven_cities_events.413
		10 = seven_cities_events.414

		2000 = 0
	}
}

on_conquistador_native = {
	random_events = {
		10 = seven_cities_events.300
		10 = seven_cities_events.301
		10 = seven_cities_events.303
		10 = seven_cities_events.304
		10 = seven_cities_events.305
		10 = seven_cities_events.306
		10 = seven_cities_events.307
		10 = seven_cities_events.308
		10 = seven_cities_events.309
		10 = seven_cities_events.310

		250 = 0
	}
}

on_buy_religious_reform = {
	events = {
		religious_reforms.1
		religious_reforms.2
		religious_reforms.3
	}
}

on_circumnavigation = {
	events = {
		exploration_events.17
		exploration_events.16 #First Circumnavigation Europe
	}
}

on_become_free_city = {
	events = {
		free_cities.1
	}
}

on_remove_free_city = {
	events = {
		free_cities.2
	}
}

on_revoke_estate_land_ai = { #AI can't handle the rebels atm or perform a gradual revoke, sorry
	add_province_modifier = {
		name = revoked_estate_modifier
		duration = 5475 #15 years
	}
}

on_revoke_estate_land = {
	add_province_modifier = {
		name = revoked_estate_modifier
		duration = 5475 #15 years
	}
	if = {
		limit = {
			has_estate = estate_cossacks
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_cossacks
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = cossack_rebels
			size = 1
		}
		province_event = { id = cossack_estate_events.15 }
	}
	if = {
		limit = {
			has_estate = estate_dhimmi
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_dhimmi
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = religious_rebels
			size = 1
		}
		province_event = { id = dhimmi_estate_events.9 }
	}
	if = {
		limit = {
			has_estate = estate_church
			has_owner_religion = yes
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_church
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = religious_rebels
			size = 1
		}
		province_event = { id = church_estate_events.11 }
	}
	if = {
		limit = {
			has_estate = estate_church
			has_owner_religion = no
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_church
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = church_estate_events.11 }
	}
	if = {
		limit = {
			has_estate = estate_nobles
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_nobles
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = noble_rebels
			size = 1
		}
		province_event = { id = nobles_estate_events.12 }
	}
	if = {
		limit = {
			has_estate = estate_burghers
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_burghers
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = burghers_estate_events.16 }
	}
	if = {
		limit = {
			has_estate = estate_nomadic_tribes
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_nomadic_tribes
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = tribal_rebels
			size = 1
		}
		province_event = { id = tribal_estate_events.10 }
	}
	if = {
		limit = {
			has_estate = estate_brahmins
			owner = {
				NOT = {
					religion = hinduism
				}
				NOT = {
					estate_loyalty = {
						estate = estate_brahmins
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = religious_rebels
			size = 1
		}
		province_event = { id = brahmins_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_brahmins
			owner = {
				religion = hinduism
				NOT = {
					estate_loyalty = {
						estate = estate_brahmins
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = brahmins_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_vaisyas
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_vaisyas
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = vaisyas_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_rajput
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_rajput
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = noble_rebels
			size = 1
		}
		province_event = { id = rajputs_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_jains
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_jains
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = particularist_rebels
			size = 1
		}
		province_event = { id = jains_estate_events.1 }
	}
	if = {
		limit = {
			has_estate = estate_maratha
			owner = {
				NOT = {
					estate_loyalty = {
						estate = estate_maratha
						loyalty = 40
					}
				}
			}
		}
		spawn_rebels = {
			type = noble_rebels
			size = 1
		}
		province_event = { id = marathas_estate_events.1 }
	}
}

on_revoke_estate_land_ai_post = {
	add_local_autonomy = 25
}
on_revoke_estate_land_post = {
	add_local_autonomy = 25
}

on_grant_estate_land = {
	if = {
		limit = {
			has_province_modifier = revoked_estate_modifier
		}
		remove_province_modifier = revoked_estate_modifier
	}
}

on_death_has_harem = {
	if = {
		limit = {
			has_heir = no
		}
		country_event = { id = harem_events.2 }
	}
}

on_select_heir_from_harem = {
}

on_fetishist_cult_change = {
	country_event = { id = fetishist_flavor.302 days = 10 } #removing tomb if incompatible cult is picked
	country_event = { id = fetishist_flavor.304 days = 10 } #rebuilding tomb if lost
	if = {
		limit = {
			has_country_flag = lost_ancestral_lands
			NOT = { has_adopted_cult = zanahary_cult }
			NOT = { has_adopted_cult = central_african_ancestor_cult }
		}
		clr_country_flag = lost_ancestral_lands
	}
}

# country
on_gain_great_power_status = {
	if = {
		limit = {
			NOT = { has_country_flag = became_great_power_flag }
		}
		set_country_flag = became_great_power_flag
	}
}

# country
on_lose_great_power_status = {
}

# province
on_province_religion_converted = {
	on_province_religion_converted_estate_privileges_effect = yes
	if = {
		limit = {
			owner = {
				has_country_modifier = son_fetishism_as_secondary_religion
			}
			religion = shamanism
			NOT = { has_province_modifier = son_fetishism_as_secondary_religion_province }
		}
		add_province_modifier = {
			name = son_fetishism_as_secondary_religion_province
			duration = -1
			desc = son_fetishism_as_secondary_religion_province_desc
		}
	}
	else_if = {
		limit = {
			OR = {
				owner = {
					NOT = { has_country_modifier = son_fetishism_as_secondary_religion }
				}
				NOT = { religion = shamanism }
			}
			has_province_modifier = son_fetishism_as_secondary_religion_province
		}
		remove_province_modifier = son_fetishism_as_secondary_religion_province
	}
	judaism_on_province_change_religion_or_change_owner_effect = yes
}

# province
on_province_culture_converted = {
	on_province_culture_converted_estate_privilges_effect = yes
	judaism_on_province_culture_converted_effect = yes
	kongo_on_province_change_culture_or_change_owner_effect = yes
}

# THIS = Province, FROM = Country who Propogated
on_convert_by_trade_policy = {
	if = {
		limit = {
			trade_company_region = trade_company_moluccas
			FROM = { is_defender_of_faith = yes }
		}
		FROM = {
			if = {
				limit = {
					ai = no
					NOT = { check_variable = { which = religion_propagated_in_moluccas value = 1 } }
				}
				set_variable = {
					which = religion_propagated_in_moluccas value = 1
				}
			}
			else_if = {
				limit = {
					ai = no
					check_variable = { which = religion_propagated_in_moluccas value = 1 }
					NOT = { check_variable = { which = religion_propagated_in_moluccas value = 6 } }
				}
				change_variable = {
					which = religion_propagated_in_moluccas value = 1
				}
			}
		}
	}
}

# province
# FROM = old owner
on_province_owner_change = {
	events = {
		japan.1
	}
	
	if = {
		limit = {
			OR = {
				has_province_modifier = wine_bonus_prod
				has_province_modifier = grain_bonus_prod
			}
			FROM = { has_reform = monastic_breweries_reform }
			NOT = { owner = { has_reform = monastic_breweries_reform } }
		}
		remove_province_modifier = wine_bonus_prod
		remove_province_modifier = grain_bonus_prod
	}
	
	if = {
		limit = {
			NOT = {
				OR = {
					has_province_modifier = wine_bonus_prod
					has_province_modifier = grain_bonus_prod
				}
			}
			owner = { has_reform = monastic_breweries_reform }
			NOT = { FROM = { has_reform = monastic_breweries_reform } }
		}
		hidden_effect = {
			if = {
				limit = {
					trade_goods = wine
				}
				add_province_modifier = { 
					name = wine_bonus_prod
					duration = -1
					hidden = yes
				}
			}
			if = {
				limit = {
					trade_goods = grain
				}
				add_province_modifier = { 
					name = grain_bonus_prod
					duration = -1
					hidden = yes
				}
			}
		}
	}

	if = {
		limit = {
			owned_by = SRU
			exists = ARA
		}
		ARA = {
			set_country_flag = ARA_defeat_saruhan
		}
	}
	if = {
		limit = {
			NOT = { owner = { religion_group = muslim } }
			has_province_modifier = sufi_shrine
		}
		remove_province_modifier = sufi_shrine
	}
	on_province_owner_change_estate_privileges_effect = yes
	judaism_on_province_change_religion_or_change_owner_effect = yes
	kongo_on_province_change_culture_or_change_owner_effect = yes
	
	if = {
		limit = {
			region = indo_china_region
			has_building = farm_estate
			trade_goods = grain
			owner = {
				has_mission = mnd_khm_irrigation 
				NOT = {
					OR = {
						has_estate = estate_vaisyas
						has_estate = estate_burghers
					}
				}
			}
		}
		add_province_modifier = {
			name = grain_production_improved
			duration = 7300
		}
	}

	if = {
		limit = {
			trade_goods = gold
			NOT = { has_province_modifier = estate_burghers_control_over_gold_mine }
			owner = {
				has_estate_privilege = estate_burghers_control_over_the_mint
			}
		}
		add_province_modifier = {
			name = estate_burghers_control_over_gold_mine
			duration = -1
		}
	}
	if = {
		limit = {
			owner = {
				religion = ROOT
				culture_group = ROOT
				has_estate_privilege = estate_church_one_faith_one_culture
			}
			NOT = { has_province_modifier = estate_church_united_faith_and_culture }
		}
		add_province_modifier = {
			name = estate_church_united_faith_and_culture
			duration = -1
		}
	}
	if = {
		limit = {
			owner = {
				NOT = { culture_group = ROOT }
				has_owner_accepted_culture = no
				has_estate_privilege = estate_church_one_faith_one_culture
			}
			NOT = { has_province_modifier = estate_church_false_culture }
		}
		add_province_modifier = {
			name = estate_church_false_culture
			duration = -1
		}
	}
	if = {
		limit = {
			owner = {
				has_country_modifier = son_fetishism_as_secondary_religion
			}
			religion = shamanism
			NOT = { has_province_modifier = son_fetishism_as_secondary_religion_province }
		}
		add_province_modifier = {
			name = son_fetishism_as_secondary_religion_province
			duration = -1
			desc = son_fetishism_as_secondary_religion_province_desc
		}
	}
	
	if = {
		limit = {
			province_id = 379
			owner = {
				NOT = { religion = jewish }
			}
		}
		remove_country_modifier = third_temple_country_modifier
	}
	else_if = {
		limit = {
			OR = {
				owner = {
					NOT = { has_country_modifier = son_fetishism_as_secondary_religion }
				}
				NOT = { religion = shamanism }
			}
			has_province_modifier = son_fetishism_as_secondary_religion_province
		}
		remove_province_modifier = son_fetishism_as_secondary_religion_province
	}
}

# country
on_parliament_debate_failed = {
}

# country
on_parliament_debate_succeeded = {
}

# country
on_harmonized_pagan = {
	events = {
		confucian_events.1
	}
}
on_harmonized_christian = {
	events = {
		confucian_events.2
	}
}
on_harmonized_muslim = {
	events = {
		confucian_events.3
	}
}
on_harmonized_jewish_group = {
	events = {
		confucian_events.5
	}
}
on_harmonized_zoroastrian_group = {
	events = {
		confucian_events.6
	}
}
on_harmonized_dharmic = {
	events = {
		confucian_events.4
	}
}
on_harmonized_mahayana = {
	events = {
		confucian_events.9
	}
}
on_harmonized_buddhism = { #Theravada
	events = {
		confucian_events.8
	}
}
on_harmonized_shinto = {
	events = {
		confucian_events.7
	}
}
on_harmonized_vajrayana = {
	events = {
		confucian_events.10
	}
}

# country
on_russian_sudebnik = {

}

# country
on_russian_oprichnina = {

}

# country
on_russian_streltsy = {

}

# province
on_consecrate_patriarch = {
}

# country. from = overlord
on_accept_tribute = {
}

# country. from = overlord
on_refuse_tribute = {
}

# country
on_leader_recruited = {
	if = {
		limit = {
			has_estate_privilege = estate_nobles_command_of_the_military
		}
		add_estate_influence_modifier = {
			estate = estate_nobles
			influence = 5
			duration = 3650
			desc = EST_VAL_NOBLE_LEADER
		}
	}
}

# country
on_general_recruited = {
	add_army_professionalism = 0.01
}

# country
on_admiral_recruited = {
}

# country
on_conquistador_recruited = {
}

# country
on_explorer_recruited = {
}

# THIS = Province, FROM = Country
on_regiment_recruited = {

}

# THIS = Province, FROM = Country, ROOT = Merc Unit
on_mercenary_recruited = {
	if = {
		limit = {
			OR = {
				FROM = { NOT = { has_country_flag = oyo_cavalry_do_not_consume_ap } }
				ROOT = { NOT = { mercenary_company = merc_oyo_cavalry } }
			}
		}
		FROM = {
			add_army_professionalism = -0.05
		}
	}
}

# THIS = One province in the state
on_add_pasha = {
}

# THIS = One province in the state
on_remove_pasha = {
	hidden_effect = {
		owner = {
			save_event_target_as = province_owner
		}
		remove_province_modifier = pasha_removed_modifier
	}

	area = {
		limit = { owned_by = event_target:province_owner }
		add_or_extend_province_modifier_effect = { MODIFIER = pasha_removed_modifier DURATION = 3650 }
	}
}

# THIS = Province
on_janissaries_raised = {
}

on_cawa_raised = {
}

on_revolutionary_guard_raised = {
}

on_reform_enacted = {
}

on_reform_changed = {
}

on_trade_company_investment = {
}

on_center_of_trade_upgrade = {

}

on_center_of_trade_downgrade = {

}

on_culture_promoted = {
	if = {
		limit = {
			has_estate_privilege = estate_church_one_faith_one_culture
		}
		every_owned_province = {
			limit = {
				has_province_modifier = estate_church_false_culture
				has_owner_accepted_culture = yes
			}
			remove_province_modifier = estate_church_false_culture
			if = {
				limit = {
					owner = {
						religion = PREV
					}
				}
				add_province_modifier = {
					name = estate_church_united_faith_and_culture
					duration = -1
				}
			}
		}
	}
	judaism_on_culture_promoted_effect = yes
	kongo_on_culture_promoted_effect = yes
}

# FROM = Previous Country, ROOT = Province
on_company_chartered = {
	if = {
		limit = {
			OR = {
				region = bengal_region
				region = hindusthan_region
				region = west_india_region
				region = deccan_region
				region = coromandel_region
			}
		}
		ROOT = {
			owner = {
				set_country_flag = the_coin_is_stronger_than_the_sword
			}
		}
	}
}

# ROOT = Overlord, FROM = Minor
on_dependency_gained = {
	if = {
		limit = {
			FROM = {
				has_reform = dutch_republic
			}
		}
		ROOT = {
			country_event = {
				id = dutch_republic.31
			}# States General falls under a PU
		}
	}
}

# ROOT = Overlord, FROM = Minor
on_dependency_lost = {

}

# ROOT = New vassal, FROM = Overlord
on_create_vassal = {
	if = {
		limit = {
			tag = PAP
		}
		change_government = theocracy
		change_religion = catholic
		add_government_reform = papacy_reform
		adopt_reform_progress = FROM
	}
}

# ROOT = Country establishing it
# First province in state is set
on_holy_order_established = {

}

# When a minority is expelled to a colony
# THIS = Colony, ROOT = Colony, FROM = Home province
on_minority_expelled = {

}

# THIS = Raiding country, FROM = Sea province
on_raid_coast = {
	if = {
		limit = {
			has_faction = pr_buccaneers
		}
		add_faction_influence = {
			faction = pr_buccaneers
			influence = 1
		}
	}
}

# ROOT = Tag that captured the flagship, FROM = Tag that lost the flagship
on_flagship_captured = {
	FROM = {
		set_country_flag = captured_flagship_country_flag
	}
	ROOT = {
		country_event = { id = flagship_events.2 }
		set_country_flag = trophy_hunter_flag
	}
	FROM = {
		country_event = { id = flagship_events.1 }
	}
}

# ROOT = Tag that destroyed the flagship, FROM = Tag that lost the flagship
on_flagship_destroyed = {
	FROM = {
		set_country_flag = sunk_flagship_country_flag
	}
	ROOT = {
		country_event = { id = flagship_events.4 }
	}
	FROM = {
		country_event = { id = flagship_events.3 }
	}
}

# this = Released country, FROM = Releasing country
on_country_released = {
	if = {
		limit = {
			tag = PAP
		}
		change_government = theocracy
		change_religion = catholic
		add_government_reform = papacy_reform
		adopt_reform_progress = FROM
	}
	if = {
		limit = {
			FROM = { has_reform = religious_permanent_revolution_reform }
			NOT = { tag = PAP }
		}
		change_religion = FROM
		adopt_reform_progress = FROM
		add_country_modifier = {
			name = global_holy_war_released_modifier
			duration = 3650
			hidden = yes
		}
		capital_scope = {
			change_religion = FROM
		}
	}
}

# ROOT = province, FROM = country
on_trade_good_changed = {
	on_trade_good_changed_estate_privileges_effect = yes
	if = {
		limit = {
			OR = {
				has_province_modifier = wine_bonus_prod
				has_province_modifier = grain_bonus_prod
			}
			FROM = { has_reform = monastic_breweries_reform }
			NOT = { owner = { has_reform = monastic_breweries_reform } }
		}
		remove_province_modifier = wine_bonus_prod
		remove_province_modifier = grain_bonus_prod
	}
	hidden_effect = {
		if = {
			limit = {
				trade_goods = wine
			}
			remove_province_modifier = grain_bonus_prod
			add_province_modifier = { 
				name = wine_bonus_prod
				duration = -1
				hidden = yes
			}
		}
		if = {
			limit = {
				trade_goods = grain
			}
			remove_province_modifier = wine_bonus_prod
			add_province_modifier = { 
				name = grain_bonus_prod
				duration = -1
				hidden = yes
			}
		}
	}
}

# this = country
on_loan_repaid = {
	on_loan_repaid_estate_privileges_effect = yes
}

# this = country
on_rebels_break_country = {
	add_country_modifier = {
		name = just_lost_to_rebels
		duration = 10
		hidden = yes
	}
}

# this = country
## Fires when you fire or replace your ADM advisor, in the moment before they are actually removed from their post.
## Note: Defining a new advisor here will result in the shortest appointment in history. Use on_post_adm_advisor_fired instead :)
on_pre_adm_advisor_fired = {
	if = {
		limit = {
			has_country_flag = need_to_fire_adm_advisor
		}
		set_country_flag = just_fired_adm_advisor
		remove_advisor_by_category_no_action = ADM
	}
}

# this = country
on_pre_dip_advisor_fired = {
	if = {
		limit = {
			has_country_flag = need_to_fire_dip_advisor
		}
		set_country_flag = just_fired_dip_advisor
		remove_advisor_by_category_no_action = DIP
	}
}

# this = country
on_pre_mil_advisor_fired = {
	if = {
		limit = {
			has_country_flag = need_to_fire_mil_advisor
		}
		set_country_flag = just_fired_mil_advisor
		remove_advisor_by_category_no_action = MIL
	}
}

# this = country
on_post_adm_advisor_fired = {

}

# this = country
on_post_dip_advisor_fired = {
	
}

# this = country
on_post_mil_advisor_fired = {
	
}

# this = new client state, from = parent country
on_create_client_state = {
	
}

# this = new target, from = previous target (both can be non-existent tag)
on_change_revolution_target = {
	if = {
		limit = { has_reform = junior_revolutionary_republic_reform }
		add_government_reform = revolutionary_republic_reform
	}
}

# this = curia controller (enactor of the bull)
on_golden_bull_enacted = {
	set_country_flag = enacted_golden_bull
}


# province:  spawned whenever a new owner takes over the province
# FROM = The previous owner.
on_conquest = {
	remove_named_unrest = estate_land_seized
	clr_province_flag = has_estate_unrest_flag
}

on_country_creation = {
	if = {
		limit = {
			tag = PAP
			OR = {
				NOT = {
					religion = catholic
				}
				NOT = {
					has_reform = papacy_reform
				}
				NOT = {
					government = theocracy
				}
			}
		}
		change_religion = catholic
		change_government = theocracy
		add_government_reform = papacy_reform
	}
}

on_federation_leader_change = {
	if = {
		limit = { tag = FROM }
		disband_federation = THIS
	}
	else = {
		# New strongest member becomes the new federation leader
		set_federation_leader = THIS
	}
}

#FROM = country pillaged, ROOT = country doing the pillaging
on_pillaged_capital = {
	slave_raid_pillage_capital_effect = yes
}

#FROM = country dev was transferred from, ROOT = country doing the transferring
on_transfer_development = {
}

on_colonial_type_change = {
	clr_country_flag = encourage_cash_crops_flag
}

on_estate_led_regency = {
}

on_estate_led_regency_surpassed = {
	if = {
		limit = {
			num_of_powerful_estates = 1
			has_estate_led_regency = {
				estate = any
			}
			NOT = {
				estate_led_regency_influence = 70
			}
			OR = {
				AND = {
					has_estate_led_regency = {
						estate = estate_burghers
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_church
							modifier = REFUSED_REGENCY
						}
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_nobles
							modifier = REFUSED_REGENCY
						}
					}
				}
				AND = {
					has_estate_led_regency = {
						estate = estate_church
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_burghers
							modifier = REFUSED_REGENCY
						}
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_nobles
							modifier = REFUSED_REGENCY
						}
					}
				}
				AND = {
					has_estate_led_regency = {
						estate = estate_nobles
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_burghers
							modifier = REFUSED_REGENCY
						}
					}
					NOT = {
						has_estate_loyalty_modifier = {
							estate = estate_church
							modifier = REFUSED_REGENCY
						}
					}
				}
			}
		}
		country_event = { id = estate_regency_events.1 }
	}
}

on_extended_regency = {
	random_events = {
		100 = extended_regency_events.4
		100 = extended_regency_events.5
		100 = extended_regency_events.6
		
		300 = 0
	}
}

on_estate_removed = {
	if = {
		limit = {
			has_country_modifier = dhimmi_building_restrictions
			NOT = {
				has_estate = estate_dhimmi
			}
		}
		remove_country_modifier = dhimmi_building_restrictions
	}
}

on_colonist_boosting_colony = {
	hidden_effect = {
		if = {
			limit = {
				OR = {
					religion = noreligion
					#test if colonists outnumber natives
					variable_arithmetic_trigger = {
						custom_tooltip = colonysize_is_larger_than_nativesize_tt
						export_to_variable = {
							which = vab_colonysize
							value = trigger_value:colonysize
						}
						export_to_variable = {
							which = vab_nativesize
							value = trigger_value:native_size
						}
						check_variable = {
							which = vab_colonysize
							which = vab_nativesize
						}
					}
					is_in_capital_area = yes
					OR = {
						continent = north_america
						continent = south_america
						continent = new_world
					}
					NOT = {
						OR = {
							has_dlc = "Dharma"
							has_dlc = "Wealth of Nations"
						}
					}
				}
			}
			change_religion = FROM
		}
		if = {
			limit = {
				OR = {
					culture = noculture
					#test if colonists outnumber natives
					variable_arithmetic_trigger = {
						custom_tooltip = colonysize_is_larger_than_nativesize_tt
						export_to_variable = {
							which = vab_colonysize
							value = trigger_value:colonysize
						}
						export_to_variable = {
							which = vab_nativesize
							value = trigger_value:native_size
						}
						check_variable = {
							which = vab_colonysize
							which = vab_nativesize
						}
					}
					is_in_capital_area = yes
					OR = {
						continent = north_america
						continent = south_america
						continent = new_world
					}
					NOT = {
						OR = {
							has_dlc = "Dharma"
							has_dlc = "Wealth of Nations"
						}
					}
				}
			}
			change_culture = FROM
			change_original_culture = FROM
		}
	}
}

#ROOT = converted country, FROM = country which force converts ROOT, on_action gets called on Force religion peace and Enforce Religion subject interaction
on_force_conversion = {
	#if = {	#Commented out for now because Catholicism has received a lot of buffs already.
	#	limit = {
	#		FROM = { religion = catholic }
	#	}
	#	if = {
	#		limit = { ROOT = { government_rank = 3 } }
	#		FROM = { add_papal_influence = 20 }
	#	}
	#	else_if = {
	#		limit = { ROOT = { government_rank = 2 } }
	#		FROM = { add_papal_influence = 10 }
	#	}
	#	else = {
	#		FROM = { add_papal_influence = 5 }
	#	}
	#}
}